我通过执行以下操作将按钮添加到 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 会:
#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。相反,我有uiviewcontroller
其中uitabar
。要在单击每个 uitab bar 按钮时显示视图,我正在执行以下操作
#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
如何更改以便我可以在 FirstViewController 和 SecondViewController 中执行 pushViewController。