0

ローカル通知からアプリケーションをロードするときに、そのペイロードを読み取ろうとしています。そのために、次のコードがあります。

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'

この問題を修正し、今後発生しないようにする方法について何か考えはありますか?

4

2 に答える 2

2

引き戻したビュー コントローラーが単なる UIViewController であり、期待どおりの IMTRewardsViewController ではないことを示すエラーが表示されます。ストーリーボードでカスタム クラス プロパティをそのタイプに設定してもよろしいですか?

于 2013-10-07T21:47:32.797 に答える
0

最初にキャストする必要があるかもしれません。ストーリーボードは UIViewController を返します

IMTRewardsViewController *rvc = (IMTRewardsViewController *)[storyboard instantiateViewControllerWithIdentifier:@"rewardsView"];
于 2013-10-07T21:49:49.680 に答える