A Good Approach For Multiple Detail View Controllers For Navigation-Based Projects
So I want a RootViewController that can handle a different view controller for each cell (Okay, I have my reasons not to reuse nibs here).
I can list them all up in the didSelectRowAtIndexPath like this:
if(condition){
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailViewController"
bundle:[NSBundle mainBundle]];
dvController.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
else if (condition2){
DetailViewController2 *dvController2 = [[DetailViewController2 alloc] initWithNibName:@"DetailViewController2"
bundle:[NSBundle mainBundle]];
dvContr开发者_C百科oller2.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController2 animated:YES];
[dvController2 release];
dvController2 = nil;
}
but that can be quite long and I don't know any other way to do it. Are there some sort of "special controllers" or classes that I can use to address this? I am new to iOS development so I know just a little of it.
Thanks in advance!
I think you can use a Factory Method returning an object of UIViewController
as that is the argument type of pushViewController
(as you can see in the API docs for UINavigationController). Basically you create a method expecting an int,String,Enum to tell what kind of DetailView you want to create, then it creates an object of the given DetailView implementation and returns it. Then you can push that new controller using pushViewController
.
精彩评论