15

我有一個視圖控制器,它以模態方式打開MFMailComposeViewController。當我嘗試設置郵件視圖控制器的委託父視圖控制器,我得到這樣的警告:iPhone - MFMailComposeViewController委託不兼容的類型

Assigning to 'id<UINavigationControllerDelegate>' from incompatible 
type 'MoreViewController *__strong' 

父視圖控制器絕對有MFMailComposeViewControllerDelegate在它的接口聲明和正在實施的委託方法-mailComposeController: didFinishWithResult:error:如下:

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
    NSLog(@"Delegate called"); 
} 

我真的不明白爲什麼父視圖控制器被識別爲UINavigationControllerDelegate,因爲我沒有實現這些方法,也沒有聲明它。我不會那麼擔心,但委託方法永遠不會被調用,所以我猜這個「不匹配」是問題的一部分。

如果有幫助,這是我怎麼initting郵件視圖控制器,在viewDidLoad

// MAIL 
self.mail = [[MFMailComposeViewController alloc] init]; 
self.mail.delegate = self; 

預先感謝您的任何想法。

回答

29

你想設置mailComposeDelegate而非delegate

self.mail.mailComposeDelegate = self; 

基本上,你設置delegate這是因爲從UINavigationControllerMFMailComposeViewController繼承,意味着delegate需要實現UINavigationControllerDelegate

+0

賓果,謝謝你! – Rob 2012-03-17 20:46:38

+2

沒有probs。這是我犯了很多次錯誤,至今仍然有點睏倦!你不是一個人 :-)。 – mattjgalloway 2012-03-17 20:47:09

+0

mattjgalloway,謝謝! :) – Oleg 2013-04-09 12:44:26