开发者

Three20: How to access the model in the next ViewController?

The Situation I populate my TTTableViewController with a TTListDatasource(with TTModel). My didSelectObject methods opens a TTViewController.

The Question I d like to show more informationen in the TTViewController.

1.Question: Should i hand over the datasource (and run a new query) or should i hand over a specific VO (with all information)?

2.Question: How do I acces the datasour in the new TTViewC开发者_如何学运维ontroller?

thanks,


In your TTTableViewController's didSelectRowAtIndexPath: definition, use your TTListDatasource to grab a reference to the corresponding object. Then pass it to your TTViewController. This is best accomplished by using a property of the TTViewController so that you don't have to worry about retain/releasing'ing.

@property (nonatomic, retain) TTModel *model;

and then in the didSelectRowAtIndexPath:

TTModel *model = //get the correct model
TTViewController *vc = [[TTViewController alloc] initHoweverYouWant];
vc.model = mode;

A few tips: TTViewController doesn't sound terribly descriptive, since you're (correctly) prefixing your classes. Maybe TTPhotoViewController or something may be more descriptive. Always err on the side of verbosity :)

Additionally, I find it pretty useful to just have my UITableViewController subclass implement the UITableViewDataSource protocol instead of creating a separate object, unless the exact same datasource is going to be used elsewhere for the exact same reason. This works more nicely with NSFetchedResultsController if you're using core data, as well.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜