I've implemented UINavigationController in my iphone application as main navigation interface.
When I need to add some new xib to my UINavigationController stack I have to write new method like this (example for ContactsView.xib):
- (void) switchToContactsView
{
// lazy load
if (self.contactsViewController == nil)
{
ContactsViewController *contactsController = [[ContactsViewController alloc]
initWithNibName:@"ContactsView" bundle:nil];
self.contactsViewController = contactsController;
[contactsController release];
}
[navigationController pushViewController:contactsViewController animated:YES];
}
The problem is, I have lots and lots of .xib screens in my application now now and for every new screen I have to copy and paste the same code, just changing the name of method and class names in it.
Is there some more efficient way of doing this? Like maybe create some single method that accepts parameters (xib and uiviewcontroller subclass name), so I can just call it with those parameters to load new xib and switch to it. The problem is, I don't know how to pass class name to a method (eg ContactsViewController class in the example above). Any help?