![](/img/trans.png)
[英]Force rotation of a UIViewController in a NavigationController in a TabbarController
[英]TabBarController -> NavigationController -> Multiple UIViewController (rootview controllers) using Storyboard
我正在使用具有以下結構的情節提要開發應用程序:
- TabBarController (2 Tab Bars) - Initial View Controller
o NavigationController1
• RegistrationPage - UIViewController (candidate for rootview)
• DoActivityPage - UIViewController (candidate for rootview)
o NavigationController2
• View Controller 1
首次啟動應用程序時,我想向用戶顯示RegistrationPage,隨后,用戶將看到DoActivityPage。 由於這兩個頁面處於同一級別,因此每個頁面都可能成為根視圖控制器。
我使用的是Storyboard布局,因此從視覺上講,我只能將其中一個視圖用作rootViewController,這並不能滿足我的目的。 因此,我知道我將必須以編程方式實現這一目標,並且我在Google上進行了很多嘗試,但找不到解決方法。
目前,當應用程序啟動並選擇了第一個選項卡項目時,我看到一個黑頁。 如果在AppDelegate.m中添加以下代碼,則會看到該頁面,但底部和頂部欄為空:
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
RegistrationPage *rp = [navController.storyboard instantiateViewControllerWithIdentifier:@"RegistrationPage"];
navController.viewControllers = [NSArray arrayWithObjects: rp, nil];
@Michael我之前曾嘗試過類似的代碼,但是問題是因為我正在使用情節提要,因此訪問tabBarController的唯一方法是通過以下方式:
self.window.rootViewController.tabBarController
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:self.window.rootViewController.tabBarController];
而且,當我嘗試使用上面的代碼時,我得到一個錯誤,應用程序試圖將nil視圖控制器推到目標上
通常,注冊/登錄視圖控制器未集成在選項卡欄中。
它是一個完全獨立的視圖控制器(可以包含在其自己的導航控制器中)。
應用啟動后,您應該簽入代碼是否應該打開注冊/登錄並將其作為模式視圖控制器打開。
編輯
假如你已經被初始化tabBarController
財產, registrationViewController
財產和isRegistered
返回方法BOOL
在你AppDelegate
,
將下一個代碼放入application:didFinishLaunchingWithOptions:
方法(在return YES;
之前):
if ([self isRegistered] == NO) {
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.tabBarController];
[self.tabBarController presentViewController:navController
animated:NO
completion:NULL];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.