啟動(dòng)
-
從storyboard啟動(dòng)
//獲取箭頭指向的VC UIViewController *VC;= [UIStoryboard storyboardWithName:@"Main" bundle:nil].instantiateInitialViewController; // 獲取故事板中某個(gè)VC UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *VC = [board instantiateViewControllerWithIdentifier:@"Second"];
配合XIB啟動(dòng)
MainViewController *MainVC= [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:[NSBundle mainBundle]];直接啟動(dòng)
MessageSystemViewController *msVC = [[MessageSystemViewController alloc]init];
跳轉(zhuǎn)方式
//1導(dǎo)航控制器下,使用PUSH方式
[self.navigationController pushViewController:VC animated:YES];
[self.navigationController popViewControllerAnimated:YES];
//2非導(dǎo)航控制器子類下,唯有MODLE形式的底部飛出頁(yè)面
[self presentViewController:VC animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
* PS:presentModalViewController 和presentViewController是一樣的效果未巫,都是彈出模態(tài)視圖约急。 只不過(guò)presentModalViewController被棄用了。
pushViewController 就是uinavigationcontroller推到一個(gè)新 viewController啊炊汤。相反的操作是pop系列的api正驻,是返回上層界面。
//3使用storyboard的segues方式,跳轉(zhuǎn)前會(huì)調(diào)用
//-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
// [self performSegueWithIdentifier:@"" sender:nil];手動(dòng)觸發(fā)跳轉(zhuǎn)抢腐。注意這個(gè)ID是segues的ID號(hào)姑曙,自己在線上設(shè)置的。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//目標(biāo)VC的獲取迈倍,可以進(jìn)行相關(guān)參數(shù)屬性的設(shè)置傳遞伤靠。
id vc = segue.destinationViewController;
}
//4選項(xiàng)卡UITabBarController控制器
UITabBarController *tabbarVC = [[ UITabBarController alloc ] init ];
ViewController *first= [[ViewController alloc] init ];
first.tabBarItem.title = @"控制器1 " ;
first.tabBarItem.image = [ UIImage imageNamed : @"first.png" ];
ViewController *second = [[ViewController alloc] init ];
second.tabBarItem.title = @"控制器2 " ;
second.tabBarItem.image = [ UIImage imageNamed : @"second.png" ];
// 添加子控制器(子控制器會(huì)自動(dòng)添加到UITabBarController的 viewControllers 數(shù)組中)
[tabbarVC addChildViewController:first];
[tabbarVC addChildViewController:second];
//5 將VC直接添加到window的rootVC中。啼染。簡(jiǎn)單粗暴宴合,有時(shí)候有問(wèn)題。
self.window.rootViewController = vc;