Iphone,从MonoTouch获取国家列表 [英] Iphone, Obtaining a List of countries from MonoTouch
本文介绍了Iphone,从MonoTouch获取国家列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在此处是否在MonoTouch中使用?
Is it possible to replicate what the code in here does in MonoTouch?
这是我到目前为止尝试过的:
Here is what I've tried so far:
foreach(string countryCode in NSLocale.ISOCountryCodes){
// How to convert this objective-c code to c#?
// [[NSLocale currentLocale] displayNameForKey:NSLocaleCountryCode value:countryCode]
}
推荐答案
Sadly a quick look shows that displayNameForKey:value: to be (currently as of 4.2.x) missing from MonoTouch (and MonoMac) bindings. I'll look into implementing it and will update this entry once done.
更新:可以解决缺少的绑定的源代码
UPDATE : Source code to work around the missing binding
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一起玩乐!
Adapt to your liking and have fun with MonoTouch!
p.s.我将更新绑定,以便将它包含在MonoTouch的将来版本中,并以更正确的 API;-)
p.s. I'll update the bindings so it will be included in future releases for MonoTouch in a more proper API ;-)
这篇关于Iphone,从MonoTouch获取国家列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文