views:

43

answers:

1

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

+1  A: 

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];
tomute
yes, i thought about, overwriting the initialize method, thanks.
choise