Apple 문서뿐만 아니라 유사한 스택 오버플로 문제를 잘 살펴 봤지만 탭바를 사용할 때 navigationController가 null 인 이유에 대해 계속 설명합니다. 코드에서 응용 프로그램의 대부분을 구축하려고하는데 XIB를 사용하여 navigationController를 삽입하지 않습니다.UINavigationController가 NULL입니다.
디버깅하는 동안 두 개의 탭으로 내 앱을 크게 단순화했습니다. 하나의 탭은 테이블 뷰를 유지하고 행이 터치되면 XIB의 세부 정보 페이지가 나타날 것으로 예상됩니다. 꽤 간단해야합니다. self.navigationController의 값이 자세히보기를 푸시 할 때 NULL임을 알았습니다. 그리고 물론 작동하지 않습니다. 우리는 완전히 탭 막대를 가져 왔고 단일보기 (테이블보기)에서 제대로 작동합니다. 이 인스턴스에서는 self.navigationController에 값이 있습니다. TextTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TextViewController *detailViewController = [[TextViewController alloc] initWithNibName:@"TextViewController" bundle:nil];
Text *text = [[Text alloc] init];
text = [textArray objectAtIndex:indexPath.row];
detailViewController.TextID = text.textID;
NSLog(@"Nav Controller: %@",self.navigationController);
[self.navigationController pushViewController:detailViewController animated:YES];
NSLog(@"pushed");
}
에서
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// With Tab Bars
self.tabBarController = [[UITabBarController alloc] init];
ViewController *vc1 = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
vc1.tabBarItem.title = @"Words";
vc1.tabBarItem.image = [UIImage imageNamed:@"tab_feed.png"];
TextTableViewController *vc2 = [[TextTableViewController alloc] init];
vc2.tabBarItem.title = @"Text";
vc2.tabBarItem.image = [UIImage imageNamed:@"tab_live.png"];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vc1];
NSArray* controllers = [NSArray arrayWithObjects:vc2, navController, nil];
tabBarController.viewControllers = controllers;
tabBarController.delegate = self;
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = self.tabBarController;
[window makeKeyAndVisible];
return YES;
}
나는이 문제에 관한 두 가지 질문 있어요. (1)이 줄의 목적은 무엇입니까? 그것이 출입하는 경우에는 차이를 보이지 않지만 Apple 사례에서는 빠져 있습니다.
tabBarController.delegate = self;
(2) 탭 배열을 만들 때보기 중 하나가 navigationController가됩니다. 어떤 탭인지 또는 다른 탭과 관련이 없으며 표시되지 않는지 여부가 중요합니다. 문제가있는 곳입니까?
'UINavigationController' 배열을 만들고'setViewControllers :'메서드를 사용하여'UITabBarController'에 추가하십시오. – sooper
감사합니다. scooper 이것을 확인해 보겠습니다. – ardochhigh