简体   繁体   中英

How would I go about pushing one view controller to another view controller that doesn't have a nib file?

How would I go about pushing oneviewcontroller to another viewcontroller that doesn't have a nib file?

this is what I'm currently doing. There is no nib file for UserViewController though and yet I'm still using initWithNibName:@"UserViewController"

-(IBAction)userProfile:(id)sender {

    UserViewController *userViewController = [[UserViewController alloc]
                                                            initWithNibName:@"UserViewController" bundle:nil];
    [self.navigationController pushViewController:userViewController animated:YES ];

    [userViewController release];  

}

thanks for any help!!!

You just use:

[[UserViewController alloc] init];

You can build the corresponding views in the loadView method. But check the View Controller Guide from Apple.

If you don't have any nib file you should not mention any. Please find below code :

-(IBAction)userProfile:(id)sender {

UserViewController *userViewController = [[UserViewController alloc]
                                                        init];
[self.navigationController pushViewController:userViewController animated:YES ];

[userViewController release];  

}  

You can place -(id)init method in UserViewController and set global variables.

-(IBAction)userProfile:(id)sender {

UserViewController *userVC = [[UserViewController alloc] init];

// Replace the current view controller
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
[viewControllers removeLastObject];
[viewControllers addObject:userVC];
[[self navigationController] setViewControllers:viewControllers animated:YES];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM