Iphone, Obtaining a List of countries in an NSArray

后端 未结 6 1848
暗喜
暗喜 2020-12-04 09:04

I have a menu that let\'s a user select a country. Exactly like that in the contacts.app country menu within the address field.

Does anyone know a simple way of get

6条回答
  •  执笔经年
    2020-12-04 09:35

    You might want to define locale..
    and there is too much autoreleased memory, which might be critical, ye never know. so create autoreleased pool inside the for loop as well. I've this:

    NSMutableArray * countriesArray = [[NSMutableArray alloc] init]; 
    NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier: @"en_US"] autorelease];
    
    NSArray *countryArray = [NSLocale ISOCountryCodes]; 
    for (NSString *countryCode in countryArray) 
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        NSString *displayNameString = [locale displayNameForKey:NSLocaleCountryCode value:countryCode];
        [countriesArray addObject:displayNameString];
        [pool release];
    
    }
    
    [countriesArray sortUsingSelector:@selector(compare:)];
    

提交回复
热议问题