开发者

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

开发者 https://www.devze.com 2022-12-14 23:06 出处:网络
I have a tableview populated fro开发者_Python百科m a plist and I want to display a detail UIView for a selected row.

I have a tableview populated fro开发者_Python百科m 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];

}
0

精彩评论

暂无评论...
验证码 换一张
取 消