当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - commit object to next TableViewController

问题描述:

i got a tableview controller.

if a cell is selected i perform the following:

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

ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain];

// Push the detail view controller.

[[self navigationController] pushViewController:singleCatTableViewController animated:YES];

[singleCatTableViewController release];

}

i want to commit an object to the next view controller that slides in after this row is selected.

do i have to do something like this?

ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain];

[singleTableViewController setMyObject:superDuperObject];

or is there an easier way to do something like that?

i need this object directly after this tableviewcontroller is initialized, to fill it with specific data that belongs to this object.

please give me some advices.

thanks

网友答案:

You can also pass the object to the next view controller when you init the view controller.
To do so, you need to implement your own initializer for the view controller.
For example:

- (id)initWithStyle:(UITableViewStyle)style superDuper:(SuperDuper*)superDuperObject {
    if (self = [super initWithStyle:style]) {
        superDuper = superDuperObject;
    }
    return self;
}

Then,

ablogSingleCatTableViewController *singleCatTableViewController =
    [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain superDuper:superDuperObject];
分享给朋友:
您可能感兴趣的文章:
随机阅读: