2011-12-05 3 views
3

내 탐색 컨트롤러가 제대로 작동하는 데 문제가 있습니다! RootViewController에서 테이블의 셀을 클릭하면 다음 ViewController가 나타나지 않습니다.UINavigationController - 응용 프로그램이 대상에서 nil보기 컨트롤러를 밀어 넣으려고했는데 무엇이 누락 되었습니까?

오류 메시지가

"응용 프로그램이 대상 에 전무 뷰 컨트롤러를 밀어했습니다."읽고

그래서 나는, 내, 내가 아마에서 중요한 뭔가가 추측 한 잘못을 ALLOC 내가 따라하는 책.

그래서 문제는 내 RootViewController.m 여기에 나타납니다 내 AppDelegate.m에서

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    UINavigationController *navigationController= [[UINavigationController alloc]init]; 

    switch ([indexPath row]) { 

     case 0: 
      [navigationController pushViewController:kundeViewCon animated:YES]; 
      break; 

     case 1: 
      [navigationController pushViewController:kalenderViewCon animated:YES]; 
      break; 

     case 2: 
      [navigationController pushViewController:wunschViewCon animated:YES]; 
      break; 
    } 
} 

내가있는 navigationController로 RootViewController 설정하기 위해 다음과 같은 일을하고있는 중이 야 : 그래서

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

// Navigation Controller 

    RootViewController *rootViewController = [[RootViewController alloc]init]; 

    navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController]; 

    self.window.backgroundColor = [UIColor whiteColor]; 

    [self.window addSubview:navigationController.view]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

을 셀을 클릭하면 푸시 할 다른 모든 ViewController가 있습니다. 나는 내 잘못이나 내가 무엇을 놓치고 있는지를 볼 수 없다!?

어쩌면 누군가 나를 도울 수 있고 나에게 힌트를 줄 수 있습니다! 그게 좋을거야!

+1

만들어진? –

+0

이것은 모두 별개의 클래스이며 RootViewController.h보다 생성됩니다 – julesmummdry

+0

(at)를 설정할 수 없습니다. 사용자를 지정하면 (at)가 있으므로 class KundeViewController; class KalenderViewController; 클래스 WunschViewController; 인터페이스 RootViewController : UITableViewController { KundeViewController * kundeViewCon; KalenderViewController * kalenderViewCon; WunschViewController * wunschViewCon; } 끝 – julesmummdry

답변

5

RootViewController에는 이미 내비게이션 컨트롤러가 있습니다. 앱 위임자에서 만들었습니다. 셀을 선택할 때 새 탐색 컨트롤러를 만드는 것은 의미가 없습니다. 그것은 아마 다음과 같아야합니다

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    switch ([indexPath row]) { 
     case 0: 
      [self.navigationController pushViewController:kundeViewCon animated:YES]; 
      break; 
     case 1: 
      [self.navigationController pushViewController:kalenderViewCon animated:YES]; 
      break; 
     case 2: 
      [self.navigationController pushViewController:wunschViewCon animated:YES]; 
      break; 
    } 
} 

또한, 단지 있는지 확인합니다 뷰 컨트롤러 -pushViewController:animated:를 호출 할 때 ( kundleViewConkalenderViewCon & wunschViewCon 즉) 비 무기 호이다. 인스턴스 변수 또는 속성과 비슷하게 보이므로 -viewDidLoad과 같이 코드에서 먼저 할당/초기화해야합니다.

+0

대단히 감사합니다. 정말 alloc/init 내 다른 ViewControllers 전에. 이제 작동합니다! – julesmummdry

1

새 UINavigationController를 만들 필요가 없습니다. 현재 창에서 컨트롤러를 가져와야합니다. yourController이 인스턴스의 UIViewController 중 하나 (kundeViewCon, kalenderViewCon 또는 wunschViewCon) Google 직원

+0

고마워, 그래, 그게 작동하고 alloc/init 내 다른 컨트롤러가 필요했습니다. 행복! – julesmummdry

1

입니다

[self.navigationController pushViewController:yourController animated:YES]; 

:

당신은 귀하의 ViewController를 연결하지 않은 경우도 발생할 수 있습니다 :

"<Your Project> App Delegate"

하지 않으면 컨트롤러가 초기화되지 않습니다. >은 "신원 관리자"로 이동 - -> 당신의 ViewController를 선택 -

열고 XIB 파일> :

는 또한/.H 해당하는 .m 파일로의 ViewController의 클래스 이름을 변경해야 텍스트 필드 "Class"에 해당 .h/.m 파일의 이름을 입력하십시오.

은 해당 항목에 클릭을 출시 한 후 당신의 ViewController enter image description here 에 ... AppDelegate에에서 마우스 오른쪽 버튼을 클릭하고 드래그하여 앱 에의 ViewController를 연결합니다 kundeViewCon, kalenderViewCon 및 wunschViewCon 있습니다 enter image description here