gpt4 book ai didi

c# - Iphone,从 MonoTouch 获取国家列表

转载 作者:行者123 更新时间:2023-11-29 11:20:17 24 4
gpt4 key购买 nike

是否可以复制here中的代码?在 MonoTouch 中呢?

到目前为止,这是我尝试过的:

foreach(string countryCode in NSLocale.ISOCountryCodes){
// How to convert this objective-c code to c#?
// [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:countryCode]
}

最佳答案

遗憾的是,快速浏览显示 displayNameForKey:value: 是(目前从 4.2.x 开始)从 MonoTouch(和 MonoMac)绑定(bind)中丢失。我会考虑实现它,并会在完成后更新此条目。

更新:解决缺失绑定(bind)的源代码

    public void DisplayCountryCodeNames ()
{
NSLocale current = NSLocale.CurrentLocale;
IntPtr handle = current.Handle;
IntPtr selDisplayNameForKeyValue = new Selector ("displayNameForKey:value:").Handle;
foreach (var countryCode in NSLocale.ISOCountryCodes) {
using (var key = new NSString ("kCFLocaleCountryCodeKey")) {
using (var nsvalue = new NSString (countryCode)) {
string ret = NSString.FromHandle (MonoTouch.ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (handle, selDisplayNameForKeyValue, key.Handle, nsvalue.Handle));
Console.WriteLine ("{0} -> {1}", countryCode, ret);
}
}
}
}

根据您的喜好进行调整,享受 MonoTouch 带来的乐趣!

附注我将更新绑定(bind),以便它将以更适当的 API 包含在 MonoTouch 的 future 版本中;-)

关于c# - Iphone,从 MonoTouch 获取国家列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7577535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com