tranvutuan
tranvutuan

Reputation: 6109

can not pushViewController at all

I am adding a button into UITableView by doing the following

 // 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;

and goToCheckOut does :

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

When I click on the button, the log is showing

goToCheckOut

but I am not being navigated to another view controller.

Does any body know why ? Please help. Thanks


@pgb : you are rite about that some how. the uiviewcontroller in tab bar is my own view controller...However, I dont have uitabbarviewcontroller.Instead, I have uiviewcontroller with uitabar in it.To display the view when clicking on each uitab bar button, I am doing like the following

#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];
    }

}

The current structure I am having now is

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

How it is possible to change so that I can do pushViewController in First and SecondViewController.

Upvotes: 2

Views: 221

Answers (2)

tranvutuan
tranvutuan

Reputation: 6109

I found my own solution for this issue. What I did is :

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....

Upvotes: 0

pgb
pgb

Reputation: 25001

Based on your description, I would guess that the UIViewController you are setting in the tab view controller is your own view controller and not a UINavigationController.

You hierarchy needs to be:

UITabViewController
   UINavigationController
     YourCustomViewController
   UINavigationController
     OtherCustomViewController

Instead, my guess is that you have the following hierarchy:

UITabViewController
   YourCustomViewController
   OtherCustomViewController

self.navigationController might not be nil, since you may be creating a UINavigationController, but you are -again, my guess- failing to set the navigationController as the view controller handled by the tab view controller.

Upvotes: 1

Related Questions