【问题标题】:UINavigationController facing some problemsUINavigationController 面临一些问题
【发布时间】: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]" 你为什么要这样做?只需按照应有的方式使用 UINavigationControllerinitWithRootViewController:,或者在 Interface Builder 中创建一个并将其 Nib Name 设置为您的控制器类。永远不要用init 创建一个,init 不在类文档中,所以你不应该认为你可以使用它。

标签: iphone uinavigationcontroller


【解决方案1】:

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

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

您做错了:您将导航控制器的视图添加到视图控制器的视图中!

【讨论】:

  • 我应该使用哪个 rootview 控制器?我想从 SAPRetailExCustomerDetailViewTVC -> SAPRetailExCustomerSalesOrderDetailViewTVC 导航,两者都是 UIViewController。
  • 不,对不起,我明白了...我添加了 SAPRetailExCustomerDetailViewTVC 作为我的 UINAvigationController 的根 wiew 控制器。非常感谢
  • 不,对不起,我明白了...我添加了 SAPRetailExCustomerDetailViewTVC 作为我的 UINAvigationController 的根 wiew 控制器。非常感谢 SAPRetailExCustomerDetailViewTVC *customerDetailViewTVC = [[SAPRetailExCustomerDetailViewTVC alloc] initWithNibName:@"SAPRetailExCustomerDetailViewTVC" bundle:nil]; // 更新拆分视图控制器的视图控制器数组。 newdetailViewController = customerDetailViewTVC; UINavigationController *cusotmerDetailNavigationController =[[UINavigationController alloc] initWithRootViewController:newdetailViewController ];
  • 在 IB 中设置导航控制器更容易,但它现在可以正常工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多