UINavigationController面临一些问题

时间:2011-09-02 05:15:30

标签: iphone uinavigationcontroller

我有UIView控制器类,我已经以编程方式创建了一个UINAvigationController

- (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中的后退按钮。 是因为我的导航栏没有标题。我将如何设置标题? 有人能帮助我吗?

1 个答案:

答案 0 :(得分:1)

您的UIViewcontroller应该是导航控制器的子项,而不是相反。您的UIViewController不对其自己的导航控制器负责。

使用UINavigationController的-initWithRootViewController:您在其中创建UIViewController对象并将导航控制器的视图添加到窗口。

您正在做的是错误的:您将导航控制器的视图添加到视图控制器的视图中!