0

大家好,我知道这个论点已经被分享了,当我尝试使用这段代码时,我的应用程序崩溃了:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){

    SLComposeViewController *facebook = [SLComposeViewController
                                                  composeViewControllerForServiceType:SLServiceTypeFacebook];



    [facebook setInitialText:@"https://itunes.apple.com"];
    [self presentViewController:facebook animated:YES completion:Nil];

    [facebook setCompletionHandler:^(SLComposeViewControllerResult result) {
        NSString *outPut = nil;

        switch (result) {
            case SLComposeViewControllerResultCancelled:
                outPut =@"Action Cancelled";
                break;
            case SLComposeViewControllerResultDone:
                outPut = @"Posted Successfully";
                break;
            default:
                break;

}

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:outPut delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
        [alert show];



    }];

}

以下是我的崩溃报告:

2013-06-25 12:41:24.112 MyApp[11779:1cd03] -[AboutViewController Facebook:]: unrecognized selector sent to instance 0x9c649d0
2013-06-25 12:41:24.114 MyApp[11779:1cd03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AboutViewController Facebook:]: unrecognized selector sent to instance 0x9c649d0'
*** First throw call stack:
(0x1a67012 0x12d3e7e 0x1af24bd 0x1a56bbc 0x1a5694e 0x12e7705 0x21b2c0 0x21b258 0x2dc021 0x2dc57f 0x2db6e8 0x24acef 0x24af02 0x228d4a 0x21a698 0x2ba0df9 0x2ba0ad0 0x19dcbf5 0x19dc962 0x1a0dbb6 0x1a0cf44 0x1a0ce1b 0x2b9f7e3 0x2b9f668 0x217ffc 0x2afd 0x2a25)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

还引发了崩溃,它会自动将我带到显示此行的主页上

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
signal SIGBART

我还想说,我是编程新手,可能你们都会注意到对你们所有人的错误是简单的识别。如果你们中的一些人能与我分享你的知识并帮助我找到崩溃的解决方案,我将不胜感激。

提前致谢!

4

1 回答 1

1

您的 .h 文件中似乎AboutViewController没有定义方法。Facebook:仔细看它Facebook:的冒号。这意味着您的方法应该有一个参数。

希望这可以帮助。

提示:每当您unrecognized selector的应用程序崩溃时。这意味着您的方法未在您的类中定义或不可用。请记住,私有方法不能通过类对象访问。

在此处了解有关私有方法的更多信息。 在 Objective-C 中为类定义私有方法的最佳方法

顺便说一句,欢迎使用 stackoverflow :)

于 2013-06-25T11:15:26.287 回答