0

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

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

3 Comments

Hi @pratikshabhisikar , I think I know where your coming from, but I'm still getting errors...I've edited my post to include this, can you help? Thanks, Jack
Can you try the same code by skipping the line '[self presentModalViewController: currentView animated:YES];' ?
Yes, that worked, strange, I'm certain I tired that last night and it didn't..Never-mind. Anyway thanks a lot @pratikshabhisikar, problem solved!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.