Reputation: 1555
I have a view based project with a set of buttons.
When one of the buttons is pressed I would like a table view with a Navigation controller to be created. I have this code in another project.
My code is basically this tutorial with some minor changes (just the first 2 parts): CODE
Is there a way to import this code into my main project so that when the button is pressed the preceding code executes?
EDIT:
I use this method to allow me to change views:
- (void) displayView:(int)intNewView{
NSLog(@"%i", intNewView);
[currentView.view removeFromSuperview];
[currentView release];
switch (intNewView) {
case 1:
currentView = [[View1 alloc] init];
break;
case 2:
currentView = [[View2 alloc] init];
break;
case 3:
currentView = [[View3 alloc] init];
break;
case 4:
currentView = [[View4 alloc] init];
break;
case 5:
vc = [[RootViewController alloc] init];
currentView = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController: currentView animated:YES];
break;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[self.view addSubview:currentView.view];
[UIView commitAnimations];
}
RootViewController is the correct controller. If I remove the 2 lines:
currentView = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController: currentView animated:YES];
And replace vc with currentView in the rootview initialiser then the code works, and my table is displayed using my custom cells and successfully parses the xml and displays the correct data, but without a navigation controller. However when I add the 2 lines above the table view doesnt work and I get an XML error code 5...Any ideas?
Thanks,
Jack
Upvotes: 0
Views: 2201
Reputation:
You can create a controller (which has your table view) and then create a navigation controller with its root controller as the controller having the table view. And from here you can present this navigation controller.
Navigation controller has a method called as
- (id)initWithRootViewController:(UIViewController *)rootViewController
UPDATE:
// Create your root controller.
RootController *controller = [[RootController alloc] initWithNibName:@"RootControllerNibName" bundle:nil];
// Create your navigation controller with its root controller.
UInavigationController *navController = [UINavigationController initWithRootViewController:controller];
// Present your navigation controller.
[self presentModalViewController: navController animated:YES];
// Release root controller and nav controller...
Upvotes: 1