messageComposeViewController didFinishWithResult委托方法未被调用

时间:2015-02-09 23:24:01

标签: ios objective-c delegates

我有一个视图控制器“Paircontroller”,它提供了一个MFMessageComposeViewController,如下所示:

NSArray *recpts = [[NSArray alloc]initWithObjects:phone.text, nil];

MFMessageComposeViewController *mcontr = [[MFMessageComposeViewController alloc]init];
mcontr.body = @"Sign up for our app!";
mcontr.recipients = recpts;
mcontr.subject = @"hey!";
mcontr.delegate = self;
[self presentViewController:mcontr animated:YES completion:^{
}];

此视图控制器的界面如下所示:

@interface PairViewController : UIViewController<UITextFieldDelegate,CustomIOS7AlertViewDelegate, UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate>

@end

在view-controller的实现中,我定义了委托方法 - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

如下:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;
        case MessageComposeResultFailed:
            NSLog(@"unknown error sending m");
            break;
        case MessageComposeResultSent:
            NSLog(@"Message sent successfully");

            break;
        default:
            break;
    }
    [self dismissViewControllerAnimated:YES completion:^{}];
}

但是,没有调用委托方法(没有命中断点,也没有命中NSLog)。

有人可以帮我解释为什么这不起作用吗?

谢谢!

C

1 个答案:

答案 0 :(得分:9)

我认为以下更改应该有效。 MFMessageComposeViewControllerUINavigationController个子类,因此在您的原始代码中,您将UINavigationControllerDelegate设置为自我。

mcontr.messageComposeDelegate = self;