tags:

views:

293

answers:

2

UITableViewController has an initWithStyle method where you pass it the style you want the table view to use, plain or grouped. These means that to create and use my table view controller, somewhere else in the code, possibly in multiple places, I do this:

MyViewController *myViewController = [[MyViewController alloc] initWithStyle: UITableViewStyleGrouped];
[self.navigationController pushViewController: myViewController animated: YES];
[myViewController release];

These seems backwards to me. The classes that use my UITableViewController should not know or care if it used grouped or plain style, that is a concern that the MyViewController should take care of. What's the idiomatic way of dealing with this? Override the init method in MyViewController to call initWithStyle?

A: 

Just be careful when overriding one init method on a superclass that calls another. I'm not sure about it here, but IF initWithStyle allready calls init in the superclass when you override init in the subclass and call the super you might have a loop on your hands.

Brad Smith
A: 

My answer as a newbie is 'just do it' and worry about the philosophical design issues later. All the examples I've seen, including popular books have that 'pattern' so it can't be too wrong.

kindaran
Yeah, that's what I'm doing, I'm just looking for some feedback from some other developers to see what best practices they are coming up with
pjb3
No prob. I've found myself asking similar questions about the 'best' way to do some things (like what object should own the model in the MVC pattern). I spend hours trying to make it work and fairly often doesnt (still new). Then I think - why am I doing this? For now I'll just do what works, and I can review it later when I know/understand more.
kindaran