2012-04-09 75 views
0

我有一個tabBarApplication,我有作爲有每個選項卡上UINavigation模板的模板。建立在一個UIViewController一個UINavigation控制器rootView

我想使用的樣品(那種),並將其轉換成一個單一的UIViewController在諾特爾應用。我已經提交了兩段代碼,第一段是我的模板,而後者是我正在做的。任何人都可以給我一些提示或幫助如何做到這一點?我不斷收到錯誤,但它們對我來說沒有意義,因爲tabBarApp不需要聲明viewController。

第一個代碼(例子):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
[self setupFetchedResultsController]; 

if (![[self.fetchedResultsController fetchedObjects] count] > 0) { 
    NSLog(@"!!!!! ~~> There's nothing in the database so defaults will be inserted"); 
    [self importCoreDataDefaultRoles]; 
} 
else { 
    NSLog(@"There's stuff in the database so skipping the import of default data"); 
} 

// The Tab Bar 
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 

// The Two Navigation Controllers attached to the Tab Bar (At Tab Bar Indexes 0 and 1) 
UINavigationController *personsTVCnav = [[tabBarController viewControllers] objectAtIndex:0]; 
UINavigationController *rolesTVCnav = [[tabBarController viewControllers] objectAtIndex:1]; 
return YES; 
} 

第二個代碼(我試圖做):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
[self setupFetchedResultsController]; 

if (![[self.fetchedResultsController fetchedObjects] count] > 0) { 
    NSLog(@"!!!!! ~~> There's nothing in the database so defaults will be inserted"); 
    [self importCoreDataDefaultRoles]; 
} 
else { 

UIViewController *mainViewController = (UIViewController *)self.window.rootViewController; 

UINavigationController *readingsTVCnav = [[mainViewController viewController] objectAtIndex:0]; 

// Override point for customization after application launch. 
return YES; 
} 

代碼的取件都涉及到其已設定核心數據起來和工作。 這樣做的原因的變化是,我想有設置爲初始畫面,而不是tabBarConfiguration的平面圖控制器。

乾杯傑夫

編輯:我添加了圖像的清晰度

enter image description here

+0

我不清楚你的新的導航將如何工作。你的初始視圖控制器會成爲導航控制器嗎? – jonkroll 2012-04-09 23:05:52

+0

是的,我正在使用故事板,並且在UINavigation控制器中嵌入了ViewController。 – 2012-04-09 23:12:14

+0

嵌入式ViewController中有什麼?你將如何導航到你的應用程序的其他部分? – jonkroll 2012-04-09 23:17:41

回答

1

從你的描述,並在你的形象描繪什麼,你有導航控制器設置爲應用程序的根視圖控制器。所以,你可以在你的應用程序委託的didFinishLaunchingWithOptions:方法來訪問它(如果需要),如下所示:

UINavigationController *navController = (UINavigationController *)self.window.rootViewController; 

雖然您的應用程序,我不認爲有需要從應用程序委託引用導航控制器任何理由。您可以通過故事板處理所有需要的設置(除了代碼數據代碼,您說的代碼數據代碼已經工作)。

在你nagivationController的根的viewController(具有所有的按鈕),你應該從每一個按鈕,你的故事板approperiate的viewController成立了SEGUE。確保設置爲「push」,以便將視圖控制器推到navigationController的導航堆棧上。如果你需要的時候SEGUE發生子視圖控制器做任何特殊的設置,您可以實現prepareForSegue:方法是這樣的:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"ShowMyViewController"]) { 

     MyViewController *vc = (MyViewController*)segue.destinationViewController;  
     vc.title = @"My Title"; 
     vc.someProperty = @"Some Value"; 
    } 
} 

你可以(也應該)確定在故事板上每個塞格斯的具有唯一標識符,以便在調用此方法時可以識別它們。

+0

嗨jonkroll的圖像,感謝您的答案 - 當我回家我有另一個去它,並張貼我的:-)乾杯結果 – 2012-04-10 00:57:13

相關問題