I have a plist that compiles a UITableView by the key “Title”, the plist is below.The Table View populates correctly, I push a view controller with this:
- (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];
}
How do I get nextViewController above to retain some information about which object in the table was selected? In addition, how do I show the strings contained in each subtree key on the new nextViewController view? What should that ViewDidLoad look like?
Here’s what it the ViewDidLoad currently looks like for the nextViewController (description is a UILabel). Why doesn’t show @”3001 Sunset” when the “LA Place 1” row is selected:
- (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>
Looking at your Data3.plist I see it’s a dictionary of 2 items.
So in your
- (void)viewDidLoadyour code is incorrect. This should be the correct code:Now, if you want to pass data to the next controller you should add a property to your
LocationsReviewViewControllerobject.In your LocationsReviewViewController.h:
In your LocationsReviewViewController.m:
When you alloc the LocationsReviewViewController object: