要将一个UIButton放到主视图中,然后点击按钮就能跳到下一个stack。
-(IBAction)stack:(id)sender{
Page1 *button =[[Page1 alloc]init];
[self.navigationController pushViewController:button animated:YES];
}
我用的代码没实现。
是不是需要将UINavigationController 放到主视图中?或者在AppDelegate 进行一些操作?
有两点需要注意:
1.首先确保你当前button所在的viewcontroller 是在" 导航控制器栈 "中.如果不在有可能是导致无法push的原因.
解决方法:使用UINavigationController 套个马甲,假设当前button所在的控制器为vc1
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:vc1];
2.如果不是第一种原因,那就要确保代码中的Page1 这个类是继承自UIViewController 的子控制器
-(void)aboutButtonPressed {
AboutViewController *aboutView =[[AboutViewController alloc] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:aboutView animated:YES];
[aboutView release];
}
试试看,能不能实现。