1

I don't know how to solve this problem:

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

This problem is connected to screen timeout. After 30 seconds of no activity, my App have to back to the login screen, and if the user come back he have to login again. And this is my code:

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];

As you can see the problem is in the last line of this code. This part of the code which I used has been taken from: iOS perform action after period of inactivity (no user interaction)

Community
  • 1
  • 1
Tannis
  • 47
  • 1
  • 11

2 Answers2

2

The pushViewController:animated: method is a method of UINavigationController.

But your root view controller is of type ViewController which is most likely a UIViewController.

You need to change your setup so your main view controller is inside a UINavigationController and you need to make the navigation controller the window's root view controller.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • But how to change it? – Tannis Sep 12 '14 at 14:43
  • 1
    Another way would be to use maybe `presentViewController:animated:completion:`, no? If there is not at all a `UINavigationController` anywhere. – Larme Sep 12 '14 at 14:43
  • 1
    @Tannis You haven't provided enough info to tell you how to change it exactly. Are you using storyboards, xibs, or is it all done in code? – rmaddy Sep 12 '14 at 14:45
  • I'm using Storyboards. – Tannis Sep 12 '14 at 14:46
  • @Tannis I can't help with the specifics of storyboards but there are a million tutorials that can. Sind one that shows how to setup your root view controller in a navigation controller. Then your code will work without any further changes. – rmaddy Sep 12 '14 at 14:49
0

This means in storyboard the rootViewController is a navigationController sample

dopcn
  • 4,218
  • 3
  • 23
  • 32