2010-11-13 1 views
0

Основной вид моего приложения не имеет UINavigationController, но при нажатии кнопки он переходит к представлению для создания события. В этом представлении CreateEvent есть UINavigationController для перемещения по разным представлениям, необходимым для создания нового события. Отображается UINavigationController, но не может установить заголовок или добавлять какие-либо кнопки навигации, глядя на код, вы можете узнать, почему? БлагодаряUINavigationController не работает по назначению (iPhone)

CreateNewEventViewController.h

@interface CreateNewEventViewController : UIViewController { 

    UINavigationController *navigationController; 
    NewEventTableViewController *tableViewController; 
} 

CreateNewEventViewController.m

- (void)viewDidLoad { 
    [super viewDidLoad]; 


    tableViewController = [[NewEventTableViewController alloc] init]; 
    tableViewController.view.center = CGPointMake(tableViewController.view.frame.size.width/2, 
                tableViewController.view.frame.size.height/2 + 44); 
    [self.view addSubview:tableViewController.view]; 

    navigationController = [[UINavigationController alloc] init]; 
    //without this instruction, the tableView appears blocked 
    navigationController.view.frame = CGRectMake(0, 0, 320, 44); 
    navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 
    //title appears empty and buttons don't appear 
    self.navigationItem.title = @"Create event"; 

    [self.view addSubview:navigationController.view]; 

} 

NewEventTableViewController.h

@interface NewEventTableViewController : UITableViewController { 

} 

PS: Я забыл сказать, что у меня нет никакого .xib файла.

ответ

2

Предполагая, что вы хотите, чтобы вид таблицы появляться в навигационном контроллере, что вам нужно сделать что-то вроде этого:

- (void)viewDidLoad { 
    [super viewDidLoad]; 


    tableViewController = [[NewEventTableViewController alloc] init]; 
    tableViewController.view.center = CGPointMake(tableViewController.view.frame.size.width/2, 
                tableViewController.view.frame.size.height/2 + 44); 

// remove this: [self.view addSubview:tableViewController.view]; 

    navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController]; // <-- do this instead 
    //without this instruction, the tableView appears blocked 
    navigationController.view.frame = CGRectMake(0, 0, 320, 460); // <-- nav controller should fill the screen 
    navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 

    //title appears empty and buttons don't appear 
    tableViewController.navigationItem.title = @"Create event"; // <-- something like this 

    [self.view addSubview:navigationController.view]; 

} 
+0

Спасибо! наконец, это сработало, мне действительно нужно взглянуть более подробно на тему UINavigationController. Просто прокомментируйте, что настройка заголовка из tableViewController.navigationItem.title = @ «Создать событие»; не работает, но это произошло из viewDidLoad в NewEventTableViewController.m – framara