【发布时间】:2014-09-12 14:33:42
【问题描述】:
我不知道如何解决这个问题:
*** 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)
【问题讨论】:
-
rootViewController真的是UINavigationController吗?好像不是这样的。 -
那怎么改呢?
标签: ios uiviewcontroller unrecognized-selector