2015-02-09 122 views
1

我有一個視圖控制器「Paircontroller」呈現的MFMessageComposeViewController,像這樣:messageComposeViewController didFinishWithResult委託方法不會被調用

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 

內視圖控制器的實現,我已經定義了委託方法 - (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:^{}]; 
} 

但是,委託方法沒有被調用(斷點未命中,NSLogs也沒有被命中)。

有人可以幫我解釋爲什麼這不起作用嗎?

謝謝!

C

+2

該消息編輯器在發送消息後被解僱了嗎? – 2015-02-09 23:49:53

回答

8

我認爲以下的改變應該可行。 MFMessageComposeViewControllerUINavigationController的子類,所以在您的原始代碼中,您將自己設置爲UINavigationControllerDelegate

mcontr.messageComposeDelegate = self; 
+0

這是正確的答案(投票) – 2015-02-10 01:54:05

+0

謝謝,這個作品!謝謝Gabbler! :) – user2011985 2015-02-10 08:31:34

+0

不客氣。 – gabbler 2015-02-10 09:16:09

相關問題