1

首先我知道這是一個很長的問題。 REST ASSURED我試圖自己弄清楚(參見:StackOverflow #2609318)。這讓我瘋狂!如何pushviewcontroller存儲在tabbaritem中的viewcontroller?

在嘗試並未能在標準的moreNavigationController中實現我自己的編輯功能後,我決定重新實現我自己的MORE功能。

我做了以下內容:

添加我與初始化一個HOME視圖控制器:initWithRootViewController

添加3個其他默認選項卡搭配:

ResortsListViewController *resortsListViewController; 
resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil]; 
resortsListViewController.title = [categoriesDictionary objectForKey:@"category_name"]; 
resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"whatever.png"]; 
[email protected]"whatever title"; 
localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController]; 
localNavigationController.navigationBar.barStyle = UIBarStyleBlack; 
[localControllersArray addObject:localNavigationController]; 
[localNavigationController release]; 
[resortsListViewController release]; 

這些工作時,我把它們添加到的TabBar。 (即:按一下,它關係到視圖控制器)

然後我就自己多視圖控制器添加的TabBar:

MoreViewController *moreViewController; 
moreViewController = [[MoreViewController alloc] initWithNibName:@"MoreView" bundle:nil]; 
moreViewController.title = @"More"; 
moreViewController.tabBarItem.image = [UIImage imageNamed:@"more.png"]; 
[email protected]"More Categories"; 
localNavigationController = [[UINavigationController alloc] initWithRootViewController:moreViewController]; 
localNavigationController.navigationBar.barStyle = UIBarStyleBlack; 
[localControllersArray addObject:localNavigationController]; 
[localNavigationController release]; 
[moreViewController release]; 

然後

tabBarController.viewControllers = localControllersArray; 
tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack; 
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil]; 
tabBarController.delegate = self; 

這創造了必要的聯繫。好的,到目前爲止一切都很好。我有一個HOME選項卡,3個類別選項卡和一個自定義的更多選項卡 - 這些都可以工作。

在更多選項卡視圖控制器我實現了一個簡單的表視圖,顯示我在行中的所有其他選項卡。因爲我希望能夠切換他們進出標籤欄我創建他們JUST就像我上述resortslistviewcontroller(即:作爲視圖控制器在數組中)。當我拉出來,顯示在tableview中的標題(這樣用戶可以去到「視圖」),我只是做到以下幾點:

// [myGizmoClass CategoryArray] holds the array of view controller tab bar items that are NOT shown on the main screen. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ... etc... 

     UIViewController *Uivc = [[myGizmoClass plusCategoryArray] objectAtIndex:indexPath.row]; 
     cell.textLabel.text = [Uivc title]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

這是它屬於通過:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    MyGizmoClass *myGizmoClass= [MyGizmoClass sharedManager]; 

    UIViewController *tbi = [[myGizmoClass plusCategoryArray] objectAtIndex:indexPath.row]; 
    NSLog(@"%@\n",[[tbi navigationItem ]title]); 

    [self.navigationController pushViewController:tbi animated:YES]; 

} 

這是我的錯誤(「自動取款機」這個稱號對點擊的tableview細胞),所以我知道Uivc標題是拉動正確的標題,因此正確的「objectatindex」:

2010-04-09 11:25:48.222 MouseAdd ICT [47485:207]的ATM 2010-04-09 11:25:48.222 MouseAddict [47485:207] ***終止應用程序由於未捕獲的異常 'NSInvalidArgumentException' 的,原因: 「推導航控制器是 不支持'

大問題:我如何使UIViewController *tbi顯示的關聯視圖顯示並被推送到視圖中?

我在想,UIViewController是這個tbl正確的類。我不確定。但我只是想獲得視圖,所以我可以把它推到堆棧上。

有人可以幫忙嗎?

要回答kovpas的問題如下:myGizmoClass是一個單身人士(蘋果的單身myGizmo類。視圖控制器數組存儲在那裏,就像它在[localControllersArray addObject:localNavigationController];(在上面的第一個代碼片段中)一樣。它確實把它正確地拉出來,證明這一事實就是證明這一點,當我的NSLOG [Uivc title]日誌打印ATMs。這意味着plusCategoryArray正確地存儲和檢索viewController(如果實際上,這是存儲的內容)。

Pushing a navigation controller is not supported真的很困擾我。爲什麼viewController會返回navigationController,並且是否有可能強制navigationController以獲得「可推出」的視圖......或者navigationController是否包含視圖中的某些元素?

回答

4

從錯誤,它看起來好像你的Gizmo類有一個UINavigationControllers數組,而不是UIViewControllers。所以推而來:

[self.navigationController pushViewController:[[tbi viewControllers] lastObject] animated:YES]; 

如果數組與上面調用localControllers的數組相同,那麼這應該更好。或者您可以在不使用UINavigationControllers的情況下創建數組,如果您要將它們推送到更多控制器導航控制器上,則不需要它們。

+0

我需要它們,因爲它們是COS我希望能夠編輯這個列表並將同一個控制器放在一個tabbar項目上,如果我需要的話。將嘗試你的選擇。 – Jann 2010-04-09 18:51:38

+0

你是一個聖!有效!!!!檢查你的答案!非常感謝您如此快速地回答並準確填寫所需的代碼! – Jann 2010-04-09 18:53:48

+1

'[[tbi viewControllers] lastObject]'可以寫成'[tbi topViewController]' – user102008 2011-07-09 02:43:13

1

我不確定,但它看起來像當你試圖將UINavigationController推入另一個UINavigationController時出現此錯誤。你能否提供一個MyGizmoClass的實現?

相關問題