开发者

How would I load a new viewcontroller in an if statement OBJ C

开发者 https://www.devze.com 2023-03-05 13:18 出处:网络
trying to work out how I can load a new viewcontroller from within an if statement in ObjectiveC. Basically when the app first launches I want to check whether user details have been entered before o

trying to work out how I can load a new viewcontroller from within an if statement in ObjectiveC.

Basically when the app first launches I want to check whether user details have been entered before on a previous occasion, and if not go to a user details screen to do so. If the details have already been entered just proceed to the main menu screen.

My if statement:

    if (gGroupDetails != 0)
    {
        //This will 开发者_JAVA百科go to default page (main menu)
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;

    }
    else
    {

        //This will go to the edit details page
        self.window.rootViewController = self.editUser;
        [self.window makeKeyAndVisible];
        return YES;
    }

I am getting the main menu to display okay, but the user details just shows as a blank white screen.

I have set up the nibs for both viewcontrollers.

If anyone can point this newbie in the right direction?

Thanks


It looks like you're doing this from in your AppDelegate. Just use

MyNewViewController *controller = [[MyNewViewController alloc] initWithNibName:@"MyNewViewController" bundle:nil];
[self.window addSubview:controller.view];


I dont know what is gGroupDetails but i assume that its value can be negative. So you can do it this way, if you have two xib files named as 'MainViewController' and 'EditViewController' In your .m modify the init method as follows:

(id)init{
NSString* nibName = gGroupDetails > 0 || gGroupDetails < 0 ? @"MainView" : @"EditView";

    if (self = [super initWithNibName:nibName bundle:nil]) {
        self.wantsFullScreenLayout = YES;
    }
    return self;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消