0

Добрый день! Есть 5 контроллеров представления, которые у меня есть. Один из них я хочу, чтобы подтолкнуть от UITableView клетки, как это:контроллеры корневого типа и нажмите

Contacts *detailViewController = [[Contacts alloc] initWithNibName:@"Contacts" bundle:nil]; 

NSLog(@"%@",self.navigationController); 

[self.navigationController pushViewController:detailViewController animated:NO]; 

в AppDelegate я удавался добавить контроллеры просматривать корень так:

mainView = [[UINavigationController alloc] initWithRootViewController:[[MainViewController alloc] initWithNibName: @"MainViewController" bundle: nil]]; 

secondView = [[UINavigationController alloc] initWithRootViewController:[[SearchController alloc] initWithNibName: @"SearchController" bundle: nil]]; 

thirdView = [[UINavigationController alloc] initWithRootViewController:[[CitySearch alloc] initWithNibName: @"CitySearch" bundle: nil]]; 

forthView = [[UINavigationController alloc] initWithRootViewController:[[MessengerMenu alloc] initWithNibName:@"MessengerMenu" bundle:nil]]; 

fifthView = [[UINavigationController alloc] initWithRootViewController:[[Contacts alloc] initWithNibName:@"Contacts" bundle:nil]]; 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = [NSArray arrayWithObjects: mainView ,secondView, thirdView, forthView, fifthView, nil]; 

[self.window setRootViewController:tabBarController]; 

но self.navigationController в Посланника ViewController по-прежнему нулевой и толчок не происходит.

Что я делаю неправильно?

+0

Есть ли «Messenger» и «MessengerMenu» тот же контроллер? – sage444

+0

да, это то же самое – Pavel

+0

странно, см. Self.rootViewController, это может очистить ситуацию – sage444

ответ

0

Вы должны сделать выделение всех viewController с помощью UIViewController и добавить их в tabbarController.

, если вы хотите, один из них как navigationController, просто поместите его корень контроллер

В настоящее время NavigationController может быть сделана tabBarController.

mainView = [[MainViewController alloc] initWithNibName: @"MainViewController" bundle: nil]; 

secondView = [[SearchController alloc] initWithNibName: @"SearchController" bundle: nil]; 

thirdView = [CitySearch alloc] initWithNibName: @"CitySearch" bundle: nil]; 

forthView = [[MessengerMenu alloc] initWithNibName:@"MessengerMenu" bundle:nil]; 

self.navigationController =[[UINavigationController alloc] initWithRootViewController:forthView]; 
fifthView = [[Contacts alloc] initWithNibName:@"Contacts" bundle:nil]]; 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = [NSArray arrayWithObjects: mainView ,secondView, thirdView, forthView, fifthView, nil]; 



[self.window setRootViewController:tabBarController]; 
+0

он хочет добавить каждую вкладку, так как один навигационный контроллер – larva

+0

не помог, есть что-то еще. Я попытался сделать только один контроллер [self.window setRootViewController: 4thView], но при наличии большого количества контроллеров в tabBar это не – Pavel

0

Попробуйте использовать этот Alloc метод инициализации для создания NSArray из viewcontrollers,

tabBarController.viewControllers = [NSArray alloc] initWithObjects: mainView ,secondView, thirdView, forthView, fifthView, nil]; 

Или кулак создать UITabbarViewController, установите его в rootVC:

tabBarController = [[UITabBarController alloc] init]; 
[self.window setRootViewController:tabBarController]; 

затем:

mainView = [[UINavigationController alloc] initWithRootViewController: 
[[MainViewController alloc] initWithNibName: @"MainViewController" bundle: nil]]; 
secondView =[[SearchController alloc] initWithNibName: @"SearchController" bundle: nil]; 
thirdView = [[CitySearch alloc] initWithNibName: @"CitySearch" bundle: nil]; 
forthView = [[MessengerMenu alloc] initWithNibName:@"MessengerMenu" bundle:nil]; 
fifthView = [[Contacts alloc] initWithNibName:@"Contacts" bundle:nil]; 

tabBarController.viewControllers = [NSArray arrayWithObjects: mainView ,secondView, thirdView, forthView, fifthView, nil]; 
+0

все еще null в '- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { // навигация логика может идти здесь, например: // Создать контроллер следующего вида контактов * detailViewController = [[Контакты] Alloc initWithNibName: @ "Контакты" Bundle: ноль];. NSLog (@ "% @ ", self.navigationController); [self.navigationController pushViewController: detailViewController animated: NO]; } ' – Pavel

0

Надеюсь, что это сработает ....

mainView = [[MainViewController alloc] initWithNibName: @"MainViewController" bundle: nil]; 

secondView = [[SearchController alloc] initWithNibName: @"SearchController" bundle: nil]; 

thirdView = [CitySearch alloc] initWithNibName: @"CitySearch" bundle: nil]; 

forthView = [[MessengerMenu alloc] initWithNibName:@"MessengerMenu" bundle:nil]; 


UINavigationController *navmain = [[UINavigationController alloc]initWithRootViewController:mainView]; 

UINavigationController *navSecond = [[UINavigationController alloc]initWithRootViewController:secondView]; 

UINavigationController *navThird = [[UINavigationController alloc]initWithRootViewController:thirdView]; 

UINavigationController *navFourth = [[UINavigationController alloc]initWithRootViewController:forthView]; 
    //Second, third, fourth... 

    NSArray *array = [[NSArray alloc]initWithObjects:navmain, navSecond, navThird, navFourth, nil]; 
     [tabBarController setViewControllers:array]; 

//and set selectedIndex 
    [tabBarController setSelectedindex:2]; 
+0

это работает, но другие виды нет. это только thirdView представлен – Pavel

+0

Другие виды не работают? – jailani

+0

они вообще не представлены – Pavel

0

Возможно, что-то не так при добавлении viewController? Я добавляю контроллер как subview к основному виду при нажатии такой кнопки:

- (IBAction)buttonMessagePressed:(UIButton *)sender { 
    messController = [[MessengerMenu alloc] initWithNibName:@"MessengerMenu" bundle:nil]; 
    [messController.view setFrame:CGRectMake(0, 50, 300, 200)]; 

    for (UIView *theView in self.currenWeatherView.subviews) { 
     [theView removeFromSuperview]; 
    } 

    [self.currenWeatherView addSubview: messController.view]; 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^