Reputation: 42173
I have a custom class which is a UITableViewController, this is inside of a UINavigationController. Normally, when I click a cell, I push a new class onto the stack and it is fine. This time, I would like to push self onto the stack (passing a different string onLoad so that I load different content), so that I can reuse my code, is this possible? Or do I always have to create a secondary class to push?
Upvotes: 0
Views: 629
Reputation: 41
My solution:
MyViewController *viewController = [[MyViewController alloc] initWithNibName:"MyView"];
viewController.customString = @"Something else";
[self.navigationController pushViewController:viewController];
Upvotes: 1
Reputation: 26812
Rather than "pushing yourself", you can push a new instance of the same view controller yes. Simply create a new one like so:
MyViewController *viewController = [[MyViewController alloc] initWithNibName:"MyView"];
viewController.customString = @"Something else";
[self.navigationController pushViewController:viewController];
[viewController release];
I haven't tested this, and it's late so there might be bits wrong but you should be ok with that. Let me know if it works!
Upvotes: 2