0

我想modalViewControlle从应用程序的第二个屏幕显示 r,当我关闭控制器时,它应该导航到第一个屏幕。下面的代码在 iPhone 4、5 和 iPod Touch 中运行良好,但在 iPAD 中却不行。目标是当我关闭modalViewController它时,它不应该回到第二个屏幕,但它应该显示第一个屏幕。

        ShareEmail *shareEmail = [[ShareEmail alloc] initWithNibName:[NSString stringWithFormat:@"%@",xibShareEmail] bundle:nil];

        shareEmail.fromWer = @"ownPer";
        [self presentModalViewController:shareEmail animated:NO];
        [shareEmail release];

        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

在共享电子邮件课程中

[self dismissModalViewControllerAnimated:YES];
4

2 回答 2

1

您需要保留您的 shareEmail 视图控制器 - 制作合成的保留属性

你的类.h:

@property (nonatomic, retain) ShareEmail *shareEmailViewController;

你的班级.m:

@synthesize shareEmailViewController;

然后通过以下方式显示您的模态视图控制器:

ShareEmail *shareEmail = [[ShareEmail alloc] initWithNibName:[NSString stringWithFormat:@"%@",xibShareEmail] bundle:nil];
self.shareEmailViewController = shareEmail;
[self presentModalViewController:shareEmail animated:NO];
[shareEmail release];

保留的属性将防止视图控制器在使用时被释放。然后,当您稍后将其关闭时,您可以执行以下操作:

[self.shareEmailViewController dismissModalViewControllerAnimated:YES];
self.shareEmailViewController = nil;

这将在您完成后释放保留的属性并释放内存。

于 2013-08-12T16:52:44.330 回答
0

有趣的事情正在发生。您正在展示一个来自 的视图控制器self,然后您正在navigationController执行它的向后导航。至此,self我之前所说的消失了。

popViewController从您的方法中删除该presentViewController方法。

此外,您需要使用^completion处理程序方法。那是您应该放置导航控制器pop代码的地方。

-(void)present {
    ShareEmail *email = [[ShareEmail...
    //You'll need to get a weak reference to `self` in `email`
    email.modalDelegate = self; //you need to make a property in ShareEmail
    [self presentViewController:email animated:YES completion:nil];
    [email release];
}

-(void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}

//in ShareEmail.m
[modalDelegate dismiss];
于 2013-08-12T17:13:18.177 回答