我有一个通过键“Title”编译 UITableView 的 plist,plist 在下面。表格视图正确填充,我用这个推送一个视图控制器:
- (void) tableView: (UITableView*) tableView didSelectRowAtIndexPath: (NSIndexPath*) indexPath;
{
LocationsReviewViewController *nextViewController = [[LocationsReviewViewController alloc]init];
NSDictionary *rowData = [[[tableData objectAtIndex: indexPath.section] objectForKey: @"Rows"] objectAtIndex: indexPath.row];
nextViewController.title = [rowData objectForKey: @"Title"];
[self.navigationController pushViewController: nextViewController animated: YES];
}
我如何在nextViewController
上面保留一些关于选择表中哪个对象的信息?另外,如何在新nextViewController
视图上显示每个子树键中包含的字符串?ViewDidLoad 应该是什么样的?
这是 nextViewController 的 ViewDidLoad 当前的样子(描述是 UILabel)。为什么选择“LA Place 1”行时不显示@“3001 Sunset”:
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Data3" ofType:@"plist"]];
NSDictionary *subtree = [dictionary objectForKey: @"Subtree"];
description.text = [NSString stringWithFormat:@"%@",[subtree objectForKey:@"Item 2"]];
}
<array>
<dict>
<key>Rows</key>
<array>
<dict>
<key>Subtree</key>
<array>
<string>Los Angeles, CA</string>
<string>Tuesday</string>
<string>3001 Sunset</string>
</array>
<key>Title</key>
<string>LA Place 1</string>
</dict>
<dict>
<key>Subtree</key>
<array>
<string>New York, NY</string>
<string>Sunday</string>
<string>1400 Broadway</string>
</array>
<key>Title</key>
<string>NYC Place 1</string>
</dict>
<dict>
<key>Subtree</key>
<array>
<string>Austin, TX</string>
<string>Sunday</string>
<string>2400 Lamar Blvd</string>
</array>
<key>Title</key>
<string>Austin Place 1</string>
</dict>
</array>
<key>Title</key>
<string>Section1</string>
</dict>
</array>
</plist>