我有一種操作工作表UIView它調用MFMailComposeViewController後點擊一個按鈕,MFMailComposeViewController被調用並呈現成功,但它並沒有關閉時,我點擊取消和有時會崩潰,我知道這是一個已知的問題,但我已經嘗試了所有已知的修復程序,但它不適用於我。這是我的代碼:MFMailComposeViewController委託方法沒有被調用
SendFeedback.h:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface SendFeedback : UIView <UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate, UINavigationControllerDelegate>
//Useless code to the problem.
@property (nonatomic, retain) MFMailComposeViewController *feedBackComposer;
@end
SendFeedback.m:
- (void)baseInit
{
//Useless code to the problem.
feedBackComposer = [[MFMailComposeViewController alloc] init];
[feedBackComposer setMailComposeDelegate:self];
[feedBackComposer setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
[feedBackComposer setMessageBody:@"" isHTML:NO];
[feedBackComposer setSubject:@"What I Love About iBox"];
}
,並呼籲作曲家: - (無效)sendFeedbackComposer { [ self.window.rootViewController presentViewController:feedBackComposer animated:YES completion:nil]; }
予以駁回:
- (void)mailComposeController:(MFMailComposeViewController *)feedBackComposer didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
//This method doesn't get called.
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Error: %@", error);
}
編輯:所以,在這個問題上所提供的所有的答案是正確的,這是我所有的壞。我想要做的是:我有一個UINavigationController
,其中包括該視圖中的cells
的UITableView
應該可以將其作爲一個subview
,就像以前一個觸發動作片這是一個UITableView
,這種觀點還包括cells
和其中一人會做一個動作,它會調用一個MFMailComposeViewController
,它會被調用,但即使設置了委託並且所有方法都是正確的,也不會成功解除,問題的原因在於調用MFMailComposeController
的方式,我首先從超級視圖中刪除了一點,UITableView
然後提出了MFMailComposeController
,所以當我解僱郵件作曲者時,它甚至沒有給出結果而崩潰,這使我把崩潰的原因與委託方法混淆起來,騙了我。 下面的代碼:
- (void)removeView
{
if (self) {
[UIView animateWithDuration:0.3
animations:^{backgroundView.alpha = 0;}
completion:^(BOOL finished){
[UIView animateWithDuration:.3
animations:^{self.frame = CGRectMake(0, 568, 320, 568);}
completion:^(BOOL finished){[self removeFromSuperview];}];
}];
}
}
- (void)sendFeedbackComposer
{
feedBackComposer = [[MFMailComposeViewController alloc] init];
[feedBackComposer setMailComposeDelegate:self];
[feedBackComposer setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
[feedBackComposer setMessageBody:@"" isHTML:NO];
[feedBackComposer setSubject:@"What I Love About iBox"];
[self.window.rootViewController presentViewController:self.feedBackComposer animated:YES completion:nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 2: //That's the index of the MailComposer caller.
[self removeView];
[self sendFeedbackComposer];
break;
case 6:
[self removeView];
break;
default:
break;
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[feedBackComposer.presentingViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Error: %@", error);
}
感謝斯特凡·阿塔納索夫,吉姆和維塔利·S.
'sendFeedbackComposer'方法是從其他類調用? – Robert
不,來自同一班,它是一個UIView。 –
其他實施的委託從這個類是否正常工作? – Robert