2012-06-19 18 views
2

我加入一個按鈕進入的UITableView通過執行以下操作可以在任何

// Add checkOut button 
    UIView  *viewHolder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 165)]; 
    UIButton *checkOut = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    CGRect  buttonRect = CGRectMake((self.view.frame.size.width - 220.)/2, 30, 220., 44.); 

    [checkOut setTitle:@"Check out" forState:UIControlStateNormal]; 
    [checkOut addTarget:self action:@selector(goToCheckOut) forControlEvents:UIControlEventTouchUpInside]; 
    [checkOut setFrame:buttonRect]; 
    [viewHolder addSubview:checkOut]; 
    self.shoppingListTable.tableFooterView = viewHolder; 

和goToCheckOut不pushViewController:

#pragma mark - goToCheckOut 
- (void)goToCheckOut { 
    NSLog(@"goToCheckOut"); 
    AnotherViewController *controller = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil]; 
    [self.navigationController pushViewController:controller animated:YES]; 
} 

當我點擊該按鈕時,日誌中顯示

goToCheckOut 

但我沒有被導航到另一個視圖控制器。

有沒有人知道爲什麼?請幫忙。謝謝


@pgb:你是有關如何的儀式。在標籤欄中的uiviewcontroller是我自己的視圖控制器...但是,我沒有uitabbarviewcontroller.Instead,我有uiviewcontrolleruitabar在它。要點擊每個uitab欄按鈕時顯示視圖,我做了如下

#pragma mark - TabBarDelegate 
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { 
    // firstViewController section 
    if (item.tag == 0) { 
     [self.firstViewController.view removeFromSuperview]; 
     [self.secondViewControoler.view removeFromSuperview]; 
     self.title = @"First View Controller"; 
     [self.view insertSubview:self.firstViewController.view belowSubview:taBar]; 
    } 
    // secondViewController section 
    else if (item.tag == 1){ 
     [self.firstViewController.view removeFromSuperview]; 
     [self.secondViewControoler.view removeFromSuperview]; 
     self.title = @"Second View Controller"; 
     frame.origin.x  = [self horizontalCoordinateAt:item.tag + 2]; 
     [self.view insertSubview:self.secondViewControoler.view belowSubview:taBar]; 
    } 

} 

我遇到的當前結構現在是

UIViewController0 (it is also a navigationController) 
    UIViewController1 
    UIViewController2 
    UITabBar 
     FirstViewController 
     SecondViewController 

它是如何可能改變,這樣我可以在第一和SecondViewController做pushViewController。

+0

您的當前視圖控制器是否包含在導航控制器中?即'self.navigationController'不是'nil'? –

+0

我只是仔細檢查,它不是。故事是我有一個大視圖A與4 uitabBars和這個視圖(包含uitableview +結帳按鈕的視圖)是當前視圖,當我點擊第三個uitabBar – tranvutuan

+0

您的視圖不在導航控制器中?或'self.navigationController'不是零? –

回答

1

根據您的描述,我猜想您在標籤視圖控制器中設置的UIViewController是您自己的視圖控制器,而不是UINavigationController

你需要層次是:

UITabViewController 
    UINavigationController 
    YourCustomViewController 
    UINavigationController 
    OtherCustomViewController 

相反,我的猜測是,你有以下層次:

UITabViewController 
    YourCustomViewController 
    OtherCustomViewController 

self.navigationController可能不是nil,因爲你可能會創建一個UINavigationController,但是我們猜測 - 無法將navigationController設置爲由選項卡視圖控制器處理的視圖控制器。

0

我找到了我自己的解決方案來解決這個問題。我所做的是:

1. Create a delegate with a callback method in each FirstViewController and SecondViewController 
2. Make UIViewController2 conform delegate of first and second view controller 
3. Implement the method in delegate (a call back) such as pushViewController....