2014-02-18 252 views
0

一旦我的应用程序的用户发送了一封电子邮件,并看到一个UIAlert通知他们他们的电子邮件已成功发送,他们的id就像他们一样,然后通过segue被带回主屏幕。此时用户必须按下后退按钮才能实现此目的。电子邮件发送后激活segue

我感觉它应该在mailComposeController方法中实现,但我从来没有以编程方式激活一个segue。下面

我的代码给出:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{ 
    switch (result) { 
     case MFMailComposeResultCancelled: 
     { 
      [self dismissViewControllerAnimated:YES completion:nil]; 
     } 
      break; 
     case MFMailComposeResultSent: 
     { 
      [self dismissViewControllerAnimated:YES completion:nil]; 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Disclaimer", "") 
                  message:NSLocalizedString(@"Thank you for Dobbing in a Hoon. You will shortly receive an email from Council. Please be aware that the Police are responsible for actioning your requests.", "") 
                  delegate:nil 
                cancelButtonTitle:@"OK" 
                otherButtonTitles: nil]; 
      [alert show]; 
      break; 
     } 

      case MFMailComposeResultFailed: 
     { 
      [self dismissViewControllerAnimated:YES completion:nil]; 
      UIAlertView *alert_failed = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Email Failure", "") 
                  message:NSLocalizedString(@"Your Email Failed to send - Please try Again", "") 
                  delegate:nil 
                cancelButtonTitle:@"OK" 
                otherButtonTitles: nil]; 
      [alert_failed show]; 
      break; 
     } 
     default: 
      break; 
    } 


- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex; 
{ 
    if (buttonIndex != alert.cancelButtonIndex) { 
     [self performSegueWithIdentifier:@"hoonToHome" sender:self]; 
    } 

} 

回答

2

如果您只需要到流行到您的主屏幕,如果家里screeen是导航控制器根视图控制器尝试

[self.navigationContoller popToRootViewControllerAnimated:YES]; 

或者,如果你有在使用

[self performSegueWithIdentifier:@"yourSegueID" sender:nil]; 
一sugue

UPDATE

如果你想alertview的确定后过渡点击设置的报警授人以自我和implemet委托方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

在这个方法中添加上面的代码。 我想要立即转换,然后将它放在之前或之后[alert show];

+0

是否在'[alert show]'之前或之后实现了它? – scb998

+0

@ scb998我的编辑 – Johnykutty

+0

但你不能在我的mailComposeController方法中放置一个方法? – scb998

2

首先,你需要设置UIAlertView中自我的委托,并实现UIAlertView中委托方法。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 

然后打电话给你的继续。

[self performSegueWithIdentifier:@"someIdentifierDefinedInStoryboard" sender:self]; 

或者如果你指的是导航控制器的标准回动作

[self.navigationController popToRootViewControllerAnimated:YES]; 
相关问题