如何将oneviewcontroller
推送到没有nib文件的另一个viewcontroller
?
这就是我目前正在做的事情。 UserViewController
没有nib文件,但我仍在使用initWithNibName:@"UserViewController"
-(IBAction)userProfile:(id)sender {
UserViewController *userViewController = [[UserViewController alloc]
initWithNibName:@"UserViewController" bundle:nil];
[self.navigationController pushViewController:userViewController animated:YES ];
[userViewController release];
}
感谢您的帮助!!!
答案 0 :(得分:3)
答案 1 :(得分:2)
如果你没有任何nib文件,你不应该提及任何。请找到以下代码:
-(IBAction)userProfile:(id)sender {
UserViewController *userViewController = [[UserViewController alloc]
init];
[self.navigationController pushViewController:userViewController animated:YES ];
[userViewController release];
}
您可以将-(id)init
方法放在 UserViewController 中并设置全局变量。
答案 2 :(得分:0)
-(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];
}