0

我将如何推oneviewcontroller送到另一个viewcontroller没有 nib 文件的内容?

这就是我目前正在做的事情。虽然没有 nib 文件,UserViewController但我仍在使用initWithNibName:@"UserViewController"

-(IBAction)userProfile:(id)sender {

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

    [userViewController release];  

}

谢谢你的帮助!!!

4

3 回答 3

3

你只需使用:

[[UserViewController alloc] init];

您可以在方法中构建相应的视图loadView。但是请查看 Apple 的View Controller Guide

于 2012-07-18T10:58:30.680 回答
2

如果您没有任何 nib 文件,则不应提及任何文件。请找到以下代码:

-(IBAction)userProfile:(id)sender {

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

[userViewController release];  

}  

您可以在UserViewController-(id)init中放置方法并设置全局变量。

于 2012-07-18T10:58:45.347 回答
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];
}
于 2012-07-18T10:59:53.083 回答