我有一个视图控制器“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
答案 0 :(得分:9)
我认为以下更改应该有效。 MFMessageComposeViewController
是UINavigationController
个子类,因此在您的原始代码中,您将UINavigationControllerDelegate
设置为自我。
mcontr.messageComposeDelegate = self;