【发布时间】:2011-09-02 05:15:30
【问题描述】:
我有 UIView 控制器类,我在其中以编程方式创建了一个 UIAvigationController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Hmm";
navigationController = [[UINavigationController alloc] init];
//without this instruction, the tableView appears blocked
navigationController.view.frame = CGRectMake(0, 0, 768, 1004); // <-- nav controller should fill the screen
navigationController.navigationBar.barStyle = UIBarStyleDefault;
navigationController.title = @"Hello";
[navigationController.navigationBar setHidden:NO];
[self.view addSubview:navigationController.view];
CGRect frame = CGRectMake(100, 70, 200, 50);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
[button setTitle:@"Bejoy" forState:UIControlStateNormal];
[button addTarget:self action:@selector(myButtonClick:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[self.view addSubview:button];
}
现在在按钮点击事件中
- (void)myButtonClick:(id)sender {
SAPRetailExCustomerSalesOrderDetailViewTVC *customerSalesOrderDetailViewTVC = [[SAPRetailExCustomerSalesOrderDetailViewTVC alloc] initWithNibName:@"SAPRetailExCustomerSalesOrderDetailViewTVC" bundle:nil];
[navigationController pushViewController:customerSalesOrderDetailViewTVC animated:YES];
[customerSalesOrderDetailViewTVC release];
}
在输出中,视图正在导航,但按钮仍在我的视图中!!! 我还必须单击两次才能在我的 NavigationController 中获得后退按钮。 是不是因为我的导航栏没有标题。我将如何在这里设置标题? 有人可以帮我吗?
【问题讨论】:
-
"
[[UINavigationController alloc] init]" 你为什么要这样做?只需按照应有的方式使用UINavigationController:initWithRootViewController:,或者在 Interface Builder 中创建一个并将其Nib Name设置为您的控制器类。永远不要用init创建一个,init不在类文档中,所以你不应该认为你可以使用它。
标签: iphone uinavigationcontroller