简体   繁体   中英

iPhone SDK How to pass selected row from plist in tableview into a UIViewController

I have a tableview populated from a plist and I want to display a detail UIView for a selected row. I don't know how to pass the selected row to the detail view controller. Perhaps someone could advise the best way to do this. The table consist of technical terms and I want to show its definition when a row is selected. Thanks in advance.

One solution would be to create a model class representing the elements you're displaying in the table. The first table would display the term for each of the model objects. When the user selects a row, you create an instance of your detail view controller (which will have a member of the type of the model) and set the model member. Then push the detail view controller.

So in a nutshell. Have a class that models your data and use that in both of the tables.

implement the didSelectRowAtIndexPath delegate method

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{

DetailsViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:@"Details" bundle:nil];

detailsViewController.book = [books objectAtIndex:indexPath.row];


[self.navigationController pushViewController:detailsViewController animated:YES];

[detailsViewController release];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM