- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// [self setupArray];
//读取plist
NSBundle *bundle = [NSBundlemainBundle];
// 设置资源文件名称为Property List,资源类型为plist
NSString *path = [bundle pathForResource:@"StateCapital"ofType:@"plist"];
// 在plist中配置了一个NSDictionary字典,字典key为StateCapital
NSMutableDictionary *dict = [[[NSDictionaryalloc]initWithContentsOfFile:path] objectForKey:@"StateCapital"];
//初始化dataSource
dataSource = [dict objectForKey:@"States"];
//初始化states
states = [[NSMutableDictionaryalloc]initWithObjects:[dict objectForKey:@"Capitals"] forKeys:dataSource];
}
- (void)setupArray
{
states = [[NSMutableDictionaryalloc]init];
[statessetObject:@"Lansing"forKey:@"Michigan"];
[statessetObject:@"Sacremento"forKey:@"California"];
[statessetObject:@"Albany"forKey:@"New York"];
[statessetObject:@"Phoenix"forKey:@"Arizona"];
[statessetObject:@"Tulsa"forKey:@"Oklahoma"];
dataSource = [statesallKeys];
}
plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StateCapital</key>
<dict>
<key>States</key>
<array>
<string>Michigan</string>
<string>California</string>
<string>New York</string>
<string>Arizona</string>
<string>Oklahoma</string>
</array>
<key>Capitals</key>
<array>
<string>Lansing</string>
<string>Sacremento</string>
<string>Albany</string>
<string>Phoenix</string>
<string>Tulsa</string>
</array>
</dict>
</dict>
</plist>
//用plist取代setupArray