是否可以复制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/