wxr
2023-06-06 592974441a4df95fffd9167c90192da1a390b1c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using Shared.IOS.JLCountryCode;
using Foundation;
using System.Collections.Generic;
 
namespace JLCountrycode
{
    public class CountryCodeView
    {
        /// <summary>
        /// 
        /// </summary>
        private static CountryCodeView m_Current = null;
        /// <summary>
        /// 
        /// </summary>
        public static CountryCodeView Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new CountryCodeView();
                }
                return m_Current;
            }
        }
 
        /// <summary>
        /// 国家区号选择
        /// </summary>
        /// <param name="action"></param>
        public void Show(Action<string, string> action)
        {
            JLCountryCodeController mJLCountryCodeController = new JLCountryCodeController();
 
            mJLCountryCodeController.SelectCountryCodeBlock += (countryName, code) =>
            {
                action?.Invoke(countryName, code);
            };
 
            Shared.Application.currentVC.NavigationController.PushViewController(mJLCountryCodeController, true);
 
        }
 
 
        /// <summary>
        /// 选择
        /// </summary>
        /// <param name="titleStr"></param>
        /// <param name="dic"></param>
        /// <param name="action"></param>
        public void ShowSortSelection(string titleStr, Dictionary<string, List<string>> dic, Action<string> action)
        {
            try
            {
                JLSortSelectionViewController vc = new JLSortSelectionViewController();
                vc.TitleStr = titleStr;
                vc.SortedNameDict = ConvertToNativeDictionary(dic);
                vc.SortSelectionBlock += (countryName) =>
                {
                    action?.Invoke(countryName);
                };
 
                Shared.Application.currentVC.NavigationController.PushViewController(vc, true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
 
        }
 
        /// <summary>
        /// Dictionary 转 iOS原生 NSMutableDictionary
        /// </summary>
        /// <param name="dict"></param>
        /// <returns></returns>
        NSMutableDictionary ConvertToNativeDictionary(Dictionary<string, List<string>> dict)
        {
            NSMutableDictionary newDictionary = new NSMutableDictionary();
            try
            {
                //var dictDataList = new NSMutableArray();
                foreach (string key in dict.Keys)
                {
                    var value = dict[key];
                    newDictionary.Add(new NSString(key), NSArray.FromObjects(value.ToArray()));
                }
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.ToString());
            }
            return newDictionary;
        }
 
 
 
    }
}