我是一个开始的iPhone SDK程序员。我构建了一个简单的练习应用程序,我试图用来了解更多关于表格视图的信息。这是一个应用程序,从plist中加载足球队,并以球场名称和徽标以表格形式显示。攻击团队进入该团队的详细视图。添加部分到Xcode的plist用于可可触摸表视图
我想了解如何节添加到这一点,所以我可能有一对夫妇在一节团队和他人在另一部分的等
我想我需要既重结构我的plist并更改代码以从plist的不同级别读取数组?
首先,我有一个plist,包含3个词典的根数组,每个团队一个。每个字典有3个键,“名称”,“体育场”和“标志”。这工作正常。我通过加载它:
NSString *path = [[NSBundle mainBundle] pathForResource:@"teams" ofType:@"plist"];
teams = [[NSMutableArray alloc] initWithContentsOfFile:path];
然后
// Configure the cell.
NSDictionary *team = [teams objectAtIndex:indexPath.row];
cell.textLabel.text = [team objectForKey:@"name"];
NSString *imgPath = [team valueForKey:@"logo"];
cell.imageView.image = [UIImage imageNamed:imgPath];
cell.detailTextLabel.text =[team objectForKey:@"stadium"];
return cell;
没问题。但现在我想要的部分,所以我改变了我的plist到:
<array>
<dict>
<key>teams 1</key>
<array>
<dict>
<key>name</key>
<string>Packers</string>
<key>stadium</key>
<string>Lambeau Field</string>
<key>logo</key>
<string>packers.jpg</string>
</dict>
<dict>
<key>name</key>
<string>Jets</string>
<key>stadium</key>
<string>Giants Stadium</string>
<key>logo</key>
<string>jets_logo.jpg</string>
</dict>
</array>
</dict>
<dict>
<key>teams 2</key>
<array>
<dict>
<key>name</key>
<string>Cincinnati Bengals</string>
<key>stadium</key>
<string>Paul Brown Stadium</string>
<key>logo</key>
<string>bengals.jpg</string>
</dict>
</array>
</dict>
而且我不确定如何修改viewDidLoad中分配的部分,以一个的NSArray和团队“级别”到另一个阵列。