我在其中一个视图控制器中使用 UITabbarcontroller,在一个标签栏中我只需要有邮件控制器,当我这样做时,就会进入无限循环,我将如何克服它,代码相关
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[mailViewController setToRecipients:[NSArray arrayWithObject:@"k.sourish.k@gmail.com"]];
[mailViewController setSubject:@"Subject Goes Here."];
[mailViewController setMessageBody:@"Your message goes here." isHTML:NO];
[self presentModalViewController:mailViewController animated:YES];
}
else {
NSLog(@"Device is unable to send email in its current state.");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error" message:@" Please Configure Your Mail Account" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
[mailViewController release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { NSString *message = @"";
// Notifies users about errors associated with the interface
switch (result) {
case MFMailComposeResultCancelled:
message = @"Mail: canceled";
break;
case MFMailComposeResultSaved:
message = @"Mail: saved";
break;
case MFMailComposeResultSent:
message = @"Mail: sent";
break;
case MFMailComposeResultFailed:
message = @"Mail: failed";
break;
default:
message = @"Mail: not sent";
break;
}
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
[controller dismissModalViewControllerAnimated:YES];
}