开发者

UINavigationController facing some problems

I have UIView controller class where i have programmatically created a UINAvigation开发者_StackOverflow社区Controller

- (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];

    }

Now in the button click event

-  (void)myButtonClick:(id)sender {
SAPRetailExCustomerSalesOrderDetailViewTVC *customerSalesOrderDetailViewTVC = [[SAPRetailExCustomerSalesOrderDetailViewTVC alloc] initWithNibName:@"SAPRetailExCustomerSalesOrderDetailViewTVC" bundle:nil];
[navigationController pushViewController:customerSalesOrderDetailViewTVC animated:YES];
[customerSalesOrderDetailViewTVC release]; 
            }

Here in the output the view is navigating but the button remains in my view!!! Also i have to click twice to get the back button in my NavigationController. Is it because i don't have a title for my navigation bar. How will i set the title here?. Can someone help me??


Your UIViewcontroller should be the child of the navigation controller and not the other way round. Your UIViewController is not responsible for its own navigation controller.

Use UINavigationController's -initWithRootViewController: where you create your UIViewController object and add the navigation controller's view to the window.

What you are doing is wrong: You add the navigation controller's view to the view controller's one!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜