views:

83

answers:

2

Hi,

I have a certain UIViewController (ViewController1), which shows contents of a database. And I want to show another view controller(ViewController2) if the database was not loaded before.

So when user enters ViewController1 and the database was not loaded before, I want to take him to ViewController2 instead of ViewController1.

Something like this:

@implementation ViewController1

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if (isDatabaseLoaded) {show contents of ViewController1;}
    else {take user to ViewController2;}
}

How can I do it? What is the most elegant way to do this?

Thank you in advance.

+2  A: 

You have a few different options.

  1. You can push to ViewController2.

    [ViewController1.navigationController pushViewController:ViewController2 animated:YES];

  2. You can present ViewController2

    [ViewController1 presentModalViewController:ViewController2 animated:YES];

  3. You can simply swap out the view of ViewController1 to that of ViewController2

    ViewController1.view = ViewController2.view;

Brandon Schlenker
I tried the second option - presentModalViewController. But in this case the whole screen gets obscured by ViewController2. And even the tab bar gets obscured. How can I avoid this?
Ilya
Presenting a modal view is designed to do that. I dont think there is a way around it. If anyone else knows different, please feel free to chime in.
Brandon Schlenker
I've had some problems with #3. It seems like adding subviews afterwards never seems to work out properly for me.
rik.the.vik
A: 
if (!isDatabaseLoaded)
    [self.navigationController pushViewController:ViewController2 animated:YES];
Corey Floyd