单击 uiBarButton 时出错

发布于 2024-12-17 11:30:50 字数 1769 浏览 1 评论 0原文

在此处输入图像描述单击 uiBarButton 时,发生 NSInvalidArgumentException,我的代码如下:

-(IBAction) sendSms:(id)sender {

        MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
        picker.messageComposeDelegate = self;

        picker.recipients = [NSArray arrayWithObject:@"1234567890"];  
        picker.body = @"Help me";

        [self presentModalViewController:picker animated:YES];
        [picker release];
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    NSString *message = [[NSString alloc] init];
    switch(result) {
        case MessageComposeResultCancelled:
            message = [[NSString alloc] initWithFormat:@"Result: cancelled"];
            NSLog(@"Result: canceled");
            break;
        case MessageComposeResultSent:
            message = [[NSString alloc] initWithFormat:@"Result: sent"];
            NSLog(@"Result: sent");
            break;
        case MessageComposeResultFailed:
            message = [[NSString alloc] initWithFormat:@"Result: failed"];
            NSLog(@"Result: failed");
            break;
        default:
            message = [[NSString alloc] initWithFormat:@"Result: not sent"];
            NSLog(@"Result: not sent");
            break;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Status" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [message release];

    [self dismissModalViewControllerAnimated:YES];

}

错误显示 nil 模态视图控制器目标。请告诉我我的错误,我已将该 uibarButton 的操作与界面生成器中的 IBAaction 正确链接。请尽快帮助我。提前致谢。

enter image description hereOn clicking the uiBarButton,NSInvalidArgumentException occurs and my code is below:

-(IBAction) sendSms:(id)sender {

        MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
        picker.messageComposeDelegate = self;

        picker.recipients = [NSArray arrayWithObject:@"1234567890"];  
        picker.body = @"Help me";

        [self presentModalViewController:picker animated:YES];
        [picker release];
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    NSString *message = [[NSString alloc] init];
    switch(result) {
        case MessageComposeResultCancelled:
            message = [[NSString alloc] initWithFormat:@"Result: cancelled"];
            NSLog(@"Result: canceled");
            break;
        case MessageComposeResultSent:
            message = [[NSString alloc] initWithFormat:@"Result: sent"];
            NSLog(@"Result: sent");
            break;
        case MessageComposeResultFailed:
            message = [[NSString alloc] initWithFormat:@"Result: failed"];
            NSLog(@"Result: failed");
            break;
        default:
            message = [[NSString alloc] initWithFormat:@"Result: not sent"];
            NSLog(@"Result: not sent");
            break;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message Status" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [message release];

    [self dismissModalViewControllerAnimated:YES];

}

the errorr shows that nil modal view controller on target. Please tell me my error, i have linked the action of that uibarButton properly with IBAaction in interface builder. Please help me asap. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生不灭 2024-12-24 11:30:50

请检查此链接

您的 MFMessageComposeViewController 对象(选择器)未正确初始化。
此处列出了无法初始化的条件。

Please check this link.

Your MFMessageComposeViewController object (picker) is not initialized properly.
The conditions that it would fail to initialize are listed there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文