我有一个有 2 个 View 的应用程序。在第一个 View 中,我有一个按钮,当我单击该按钮时,用户应该转到第二个 View 。我尝试了 Karoley 之前解释的内容,但它不起作用。当我点击按钮时什么也没发生?
这是我的操作代码:
-(IBAction)gotoSecondPage:(id) sender{
NSLog(@"In gotoSecondPage");
LeoActionViewController *aSecondPageController =
[[LeoActionViewController alloc]
initWithNibName:@"LeoActionViewController"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:aSecondPageController animated:YES];
}
LeoActionViewCOntroller 是第二个 View 的 Controller 。 它只是不切换到第二个 View 。不知道为什么
最佳答案
我把你的问题的代码写下来,这会对你有帮助。首先,声明方法并打开 .xib 文件,然后使用选定的 touchupinside 连接连接到该按钮。
在 .h 文件中:
- (IBAction)gotoSecondPage:(id) sender;
在 .m 文件中:
- (IBAction)gotoSecondPage:(id) sender
{
NSLog(@"In gotoSecondPage");
LeoActionViewController *aSecondPageController =
[[LeoActionViewController alloc]
initWithNibName:@"LeoActionViewController"
bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:YES];
[aSecondPageController release];
}
关于iphone - 使用 UIButton 从一个 View 导航到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255862/