我创建了一个有三行的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>intro_buttons</key>
<dict>
<key>button1</key>
<string>1.1</string>
<key>button2</key>
<string>1.2</string>
<key>button3</key>
<string>1.3</string>
</dict>
<key>end_buttons</key>
<dict>
<key>button1</key>
<string>2.1</string>
<key>button2</key>
<string>2.2</string>
<key>button3</key>
<string>2.3</string>
</dict>
</dict>
</plist>
我想根据我的plist填写tableview。但我不知道如何访问每个元素。到目前为止我已经测试过,但没有运气。
cell.textLabel.text = [[contentDict objectForKey:@"intro_buttons" ]objectAtIndex:indexPath.row];
有人能指出我正确的方向吗?
答案 0 :(得分:0)
这里是:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"yourpath.plist"];
NSDictionary *plistData = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSDictionary *introButtons = [NSDictionary dictionaryWithDictionary:[plistData objectForKey:@"intro_Buttons"]];
NSString * button1 = [introButtons objectForKey:@"button1"];
确保您在资源文件夹中添加了plist ..