单击uiBarButton时出错

时间:2011-11-23 07:26:32

标签: iphone objective-c ios uibarbuttonitem ibaction

enter image description here单击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正确链接。请尽快帮助我。提前谢谢。

1 个答案:

答案 0 :(得分:0)

请检查此link

您的MFMessageComposeViewController对象(选取器)未正确初始化。 那里列出了无法初始化的条件。