15

Tôi có một bộ điều khiển xem mở MFMailComposeViewController một cách bình thường. Khi tôi cố gắng thiết lập đại biểu các bộ điều khiển xem email của bộ điều khiển xem cha mẹ, tôi nhận được cảnh báo này:iPhone - MFMailComposeViewController đại biểu loại không tương thích

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

Bộ điều khiển xem cha mẹ chắc chắn có MFMailComposeViewControllerDelegate trong tuyên bố giao diện của nó và đang triển khai các phương pháp đại biểu -mailComposeController: didFinishWithResult:error: như sau:

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

Tôi thực sự không hiểu tại sao bộ điều khiển chế độ xem gốc được nhận dạng là UINavigationControllerDelegate, vì tôi không triển khai các phương pháp đó cũng như không khai báo như vậy. Tôi sẽ không quá lo lắng về nó nhưng phương pháp đại biểu không bao giờ được gọi, vì vậy tôi đoán điều này "không phù hợp" là một phần của vấn đề.

Nếu nó giúp, đây là cách tôi đang initting bộ điều khiển xem mail, trong viewDidLoad:

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

Cảm ơn trước cho bất kỳ suy nghĩ bạn có thể có.

Trả lời

29

Bạn muốn thiết lập mailComposeDelegate hơn delegate:

self.mail.mailComposeDelegate = self; 

Về cơ bản, bạn đã thiết lập các delegate mà vì MFMailComposeViewController thừa hưởng từ UINavigationController, có nghĩa là delegate nhu cầu để thực hiện UINavigationControllerDelegate.

+0

Bingo, cảm ơn bạn !! – Rob

+2

Không có probs. Đó là một sai lầm tôi đã thực hiện rất nhiều lần và vẫn làm cho đến ngày nay khi tôi là một chút buồn ngủ! Bạn không cô đơn :-). – mattjgalloway

+0

mattjgalloway, cảm ơn bạn! :) – Oleg