我第一次喜歡加載簡單的viewController,它顯示了一些選項,然後點擊一些按鈕,我想加載navigationController或tabbarController取決於按鈕點擊。我怎樣才能做到這一點 ?如何將第一個簡單的singleview viewController更改爲navigation viewController?
回答
我想在切換視圖時替換窗口上的根視圖控制器。
例如在我的應用程序中,我先顯示一個加載屏幕,然後將視圖切換到登錄屏幕。
要做到這一點,你需要你的應用程序委託的引用,那麼你可以訪問該窗口屬性和更換根視圖控制器:在appdelgate
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
LoginViewController *loginVC = [[LoginViewController alloc] init];
appDelegate.window.rootViewController = loginVC;
點擊here。這個鏈接是關於如何創建導航控制器你想要的。我在這個鏈接中編寫了代碼。我希望這會對你有所幫助。
我不想在導航控制器中的第一個視圖RootViewController的 – 2012-04-25 09:13:12
在你simpleViewController:
- (IBAction) yourButtonAction:(id)sender
{
UIViewController *Vc = [[theViewControllerYouWantToShow alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:Vc];
[self presentModalViewController:nav animated:YES];
}
編輯:
您有三個選項,以顯示您的viewController內容:上面使用presentModalViewController:
爲例
將viewController視圖添加爲當前viewController的子視圖。 你的情況:
[simpleViewController.view addSubView:nav.view];
3.or如果你簡單的ViewController是導航根的viewController你可以把其他viewControllers它的導航堆棧。
我不使用什麼presentModelviewController,因爲我需要做一些更多的過程和我的應用程序需要改變viewControllers很多時候 – 2012-04-25 08:49:36
好的向我解釋你想要做什麼? – 2012-04-25 09:18:09
我第一次在該viewController的視圖呈現簡單的viewController我有三個按鈕點擊按鈕我想加載navigationViewController或TabBarViewController – 2012-04-25 09:22:00
在appdelegate.h
@property (strong, nonatomic) id<UIApplicationDelegate>delegate;
。 m
@synthesize delegate;
在我的第一個viewController的.h文件中
AppDelegate *myappDelegate;
-(IBAction)start:(id)sender;
在我第一次的viewController的.m文件
-(IBAction)start:(id)sender
{
NSLog(@"Start Button is clicked");
mvc = [[MasterViewController alloc]initWithNibName:@"MasterViewController" bundle:nil];
myappDelegate = [[UIApplication sharedApplication]delegate];
myappDelegate.navigationController = [[UINavigationController alloc]initWithRootViewController:mvc];
myappDelegate.window.rootViewController = myappDelegate.navigationController;
[myappDelegate.window makeKeyAndVisible];
}
- 1. 從第二個ViewController到第一個ViewController
- 2. 如何從第三個viewController返回到第一個viewcontroller?
- 3. 單擊第一個ViewController中的按鈕更改第二個ViewController的標籤文本
- 4. 如何將對象從一個ViewController傳遞到另一個ViewController
- 5. 我怎麼回到第一個viewController從第三個viewController
- 6. 從第二個ViewController回到第一個ViewController
- 7. 一個ViewController轉到另一個ViewController
- 8. 爲什麼我無法將viewcontroller推送到下一個viewcontroller?
- 9. 更改NIB中的ViewController
- 10. 如何更改viewController支持的方向?
- 11. 辭退一個的viewController到especific的viewController
- 12. 如何將單獨的TableView單元鏈接到另一個ViewController
- 13. UIBarButtonItem更改viewController的方向
- 14. iPhone ViewController影響另一個ViewController的IBOutlet
- 15. 在另一個ViewController中更改TableViewController中的單元格標題
- 16. 從子ViewController報告更改
- 17. 爲什麼我不能更改ViewController?
- 18. 在按鈕上更改viewController單擊
- 19. ViewController異常更改大小
- 20. Xcode:如何更改一個ViewController的格式並讓它們全部更改
- 21. 將一個簡單的UIView從一個類添加到主ViewController中
- 22. 從UIViewController回到第一個ViewController
- 23. 如何編碼按鈕以將ViewController從一個更改爲另一個,而不創建一個新的按鈕
- 24. Touchupinside和簡單的viewController問題
- 25. 簡單的ViewController/View,刪除白色條?
- 26. 將viewController推入另一個viewController後會發生什麼
- 27. UITableView單元到一個新的ViewController
- 28. 如何返回複雜場景中的第一個viewController?
- 29. 如何將委託設置爲另一個ViewController?
- 30. 更改在UItabbarcontroller的viewcontroller的標題
intrest,但在ios 5我得到錯誤,當我嘗試使用您的答案的代碼塊的第一行 – 2012-04-25 09:19:25
用您的應用程序委託文件的名稱替換MyAppDelegate。 MyAppDelegate是我的文件的名稱,你的將是不同的 – 2012-04-25 09:25:42
新項目的默認稱爲AppDelegate。我已經更新了我的代碼塊 – 2012-04-25 09:26:48