Simple Detail View Help?
Im having major problems with Detail views and was hoping someone could point me in the right direction.
I would like to add a det开发者_如何学Goail view to an app like apples advancetableviewcells. So once you click on a cell, it leads you to the detail view.
Only catch is, it has to load the data from the cell into the detail view also.
I've looked at allot of sites and allot of examples online, and I can see how it done with simple table but when it comes to individual cells and the data in the .plist. I'm lost.
Please any help would be great. Thanks
Adding a detail controller isn't that difficult to implement. In your root view - I guess - you collect all the data from your plist file you mentioned above and order the data after your own criterias. Why don't you create a NSArray in the root view controller which contains a NSDictionary for every cell. In that dictionary you put all the information like title, price or something else of that object. In your detail controller just add an NSDictionary property.
If you select a cell, the didSelectRowAtIndexPath
method is called. In this method you set the NSDictionary property in the detail view controller as the object in the NSArray of your root view controller at the index indexPath.row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *myDetailController = [[DetailViewController alloc] initWithNibName:@"NibBame" bundle:nil];
myDetailController.detailDict = [rootViewArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:myDetailController animated:YES];
[myDetailController release];
}
Afterwards all the data for the specific cell is now available in the detail view controller, and you can use the advantages of the NSDictionary and can get the variables just by a simple key. For example:
- (void)viewDidLoad {
self.title = [myDictionary valueForKey:@"specificKey"];
}
The table cell needs to be subclassed from UITableViewCell. You don't have to set the title of the view controller three or more times, it is always overwritten. You should set up your custom cell in the cellForRowAtIndex method and set the properties of the cell.
精彩评论