电子邮件发送后激活segue

时间:2014-02-18 05:29:18

标签: ios objective-c segue

一旦我的应用程序的用户发送了一封电子邮件,并且看到UIAlert通知他们他们的电子邮件已成功发送,就像他们一样通过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 个答案:

答案 0 :(得分:3)

如果您只需要弹出到主屏幕,如果主屏幕是导航控制器根视图控制器尝试

[self.navigationContoller popToRootViewControllerAnimated:YES];

或者如果你有使用的建议

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

<强>更新

如果您想在alertview的ok之后进行转换,请单击设置警报委托给self和implemet委托方法

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

在此方法中添加上面的代码。 我想要立即转换,然后将其放在[alert show];

之前或之后

答案 1 :(得分:2)

首先,您需要将UIAlertView的委托设置为self并实现UIAlertView委托方法。

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

然后打电话给你的segue。

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

或者,如果您指的是导航控制器的标准后退动作

[self.navigationController popToRootViewControllerAnimated:YES];