2014-09-12 1 views
0

애니메이션 :인식 할 수없는 선택기 인스턴스과 pushViewController로 전송 :이 문제를 해결하는 방법을 모른다

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController pushViewController:animated:]: unrecognized selector sent to instance 0x8e5fc70' 

이 문제는 화면 타임 아웃에 연결되어 있습니다. 활동이없는 30 초 후, 내 앱은 로그인 화면으로 돌아 가야하며, 사용자가 다시 돌아 오면 다시 로그인해야합니다. 그리고 내 코드는 다음과 같습니다.

AppDelegate.h: 

#import <UIKit/UIKit.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 
@end 


AppDelegate.m: 
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidTimeout:) name:kApplicationDidTimeoutNotification object:nil]; 

    return YES; 
} 

-(void)applicationDidTimeout:(NSNotification *) notif 
{ 
    NSLog (@"time exceeded!!"); 
    UIViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:NULL] instantiateViewControllerWithIdentifier:@"mainView"]; 

    [(UINavigationController *)self.window.rootViewController pushViewController:controller animated:YES]; 

문제는이 코드의 마지막 줄에 있습니다. 내가 사용한이 코드 부분은 다음에서 가져온 것입니다. iOS perform action after period of inactivity (no user interaction)

+1

입니다 스토리 보드에서 의미? 그렇게 보이지 않는다. – Larme

+0

그래서 어떻게 바꿀 수 있습니까? – Tannis

답변

1

pushViewController:animated: 메서드는 UINavigationController의 메서드입니다.

그러나 루트보기 컨트롤러의 유형은 ViewController이며 대체로 UIViewController입니다.

기본보기 컨트롤러가 UINavigationController 안에 있도록 설정을 변경해야하며 탐색 컨트롤러를 창의 루트보기 컨트롤러로 설정해야합니다.

+0

하지만 어떻게 바꿀 수 있습니까? – Tannis

+1

또 다른 방법은 아마'presentViewController : animated : completion :', 아니요? 어디에도 UINavigationController가없는 경우. – Larme

+1

@ Tannis 정확하게 변경하는 방법을 알려주는 정보가 충분하지 않습니다. 스토리 보드, xibs를 사용하고 있습니까? 아니면 모두 코드로 끝났습니까? – rmaddy

0

이것은 rootViewController 정말`rootViewController``UINavigationController`하는있는 navigationController sample

관련 문제