2013-10-07 47 views
0

從本地通知加載我的應用程序時,我試圖讀取其有效內容。要做到這一點,我有以下代碼:UILocalNotifcation上的'NSInvalidArgumentException'加載

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Loading Stuff 

    UILocalNotification *localNotif = 
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
    if (localNotif) { 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; 
     [(UITabBarController *)self.window.rootViewController setSelectedIndex:1]; 
     UINavigationController *nav = [[(UITabBarController *)self.window.rootViewController viewControllers] objectAtIndex:1]; 
     IMTRewardsViewController *rvc = [storyboard instantiateViewControllerWithIdentifier:@"rewardsView"]; 
     [rvc loadPushNotification:localNotif]; 
     [nav pushViewController:rvc animated:NO]; 

    } 

    return YES; 
} 

IMTRewardsController.h:

-(NSDictionary *)loadPushNotification:(UILocalNotification *)notification; 

IMTRewardsController.m:

- (NSDictionary *)loadPushNotification:(UILocalNotification *)notification 
{ 
    NSLog(@"%@",notification.userInfo); 
    return notification.userInfo; 
} 

當我打開我的應用程序從本地通知我收到以下錯誤:

<Error>: -[UIViewController loadPushNotification]: unrecognized selector sent to instance 0x14e70b30 
<Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController loadPushNotification]: unrecognized selector sent to instance 0x14e70b30' 

有關如何解決此問題並防止其在將來出現的任何想法?

回答

2

有錯誤表明你已經撤回的視圖控制器只是一個UIViewController,而不是像你期待的IMTRewardsViewController。你確定在故事板中將自定義類屬性設置爲該類型嗎?

+0

兒子的一個_____________!這正是問題所在。謝謝你,先生。 – Jeremy1026

+0

沒問題。這幾乎發生在我每一次。 – shortstuffsushi

0

您可能需要先施放它。故事板返回一個UIViewController

IMTRewardsViewController *rvc = (IMTRewardsViewController *)[storyboard instantiateViewControllerWithIdentifier:@"rewardsView"]; 
相關問題