IOS页面切换的常用方式
从一个视图控制器切换到另一个视图控制器的几种方式
- (void)goForward
{
ModalViewController * modalView = [[ModalViewControlleralloc]init];
modalView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// [self presentModalViewController:modalView animated:YES]; ios 6 弃用了该方法
[selfpresentViewController:modalView animated:YEScompletion:nil];
}
关闭模态画面的方法:
- (void)goBack
{
[self dismissViewControllerAnimated:YES completion:^{
//这里加个日志,点击按钮模态视图移除后会回到这里
NSLog(@"back"); //ios 5.0以上可以用该方法
}];
}
self.view insertSubview:(加载的新页面) atIndex:n;
对n的解释:页面都是层次叠加的,n表示加载到那一层上面
//将5个viewController实例放入TabBar的viewcontrollers属性中
self.tabBarController.viewControllers = @[navFrist, navSecond,navThird,navFourth,navFifth];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.tabBarController.view];//将根控制器的视图加到应用程序主窗口
- (IBAction)addRightAction:(id)sender
{
XAddSymbolViewController *addSymbol=[[[XAddSymbolViewControlleralloc]initWithNibName:@"XAddSymbolViewController" bundle:nil] autorelease];
[self.navigationController pushViewController:addSymbolanimated:YES];
}
返回原视图方法:
[self.navigationController popViewControllerAnimated:YES];//弹出后返回到原视图