missModalViewController 无法正常工作
我的应用程序处于工作状态,但由于某种原因,当我在关闭模态视图控制器时收到内存警告时,我的应用程序会转到 viewDidUnload 。我已经检查了所有代码,但找不到原因。
在我的应用程序中没有 UINavigationController。
MainView 的代码:
-(void) showInfo:(id) sender
{
PhotoFeatureViewController *photoGalleryViewController = [[PhotoFeatureViewController alloc] initWithNibName:@"PhotoFeatureViewController" bundle:nil];
photoGalleryViewController.modalPresentationStyle = UIModalPresentationFullScreen;
photoGalleryViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[photoGalleryViewController loadPhotogalleryImages:[itemTagArray objectAtIndex:[detailInfoBtn tag]]];
[self presentModalViewController:photoGalleryViewController animated:YES];
[photoGalleryViewController release];
}
ModalView 的代码:
-(IBAction) dismiss
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
My app is in working condition but for some reason my app goes to viewDidUnload when I receive memory warning while dismissing modal view controller. I've been through all my code and cannot find a reason for this.
In my app there is no UINavigationController.
code for MainView :
-(void) showInfo:(id) sender
{
PhotoFeatureViewController *photoGalleryViewController = [[PhotoFeatureViewController alloc] initWithNibName:@"PhotoFeatureViewController" bundle:nil];
photoGalleryViewController.modalPresentationStyle = UIModalPresentationFullScreen;
photoGalleryViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[photoGalleryViewController loadPhotogalleryImages:[itemTagArray objectAtIndex:[detailInfoBtn tag]]];
[self presentModalViewController:photoGalleryViewController animated:YES];
[photoGalleryViewController release];
}
code for ModalView :
-(IBAction) dismiss
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在解雇中,尝试:
In dismiss, try:
试试这个
Try out this
在 photoGalleryViewController 中添加关闭功能。
并像下面这样使用它:
Add dismiss function inside photoGalleryViewController.
And use it like below:
你已经得到答案了:-
[selfmissModalViewControllerAnimated:TRUE];
you already got the answer:-
[self dismissModalViewControllerAnimated:TRUE];
您是否知道 Apple 文档建议使用带有 ModalViewController 的委托?如果您仍然遇到问题,这样的不同方法可能会有所帮助:
基本上,您为以模态方式呈现的视图控制器(即 photoGalleryViewController)定义一个委托属性,并在创建 photoGalleryViewController 并以模态方式呈现它时将其设置为父视图控制器。在miss{}中,您将使用delegate(parent)来调用处理dismissModalViewController的方法。
它需要为 photoGalleryViewController 设置一个协议,并将协议和委托方法添加到父视图控制器的定义中,但这些额外的步骤并不费力,从长远来看,更好的设计可能会带来回报。
Apple 文档 - 视图控制器程序员指南 http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
关于设置模态视图的建议使用委托的控制器:
呈现模态视图控制器
Did you know that the Apple docs recommend using a delegate with a ModalViewController? If you're still having trouble a different approach like this might help:
Basically, you define a delegate property for the view controller that's being presented modally (i.e photoGalleryViewController) and set it to the parent view controller when you create photoGalleryViewController and present it modally. In dismiss{}, you would use the delegate(parent) to call a method that handles dismissModalViewController.
It requires setting up a protocol for photoGalleryViewController and adding the protocol and the delegate method to the parent view controller's definition, but those extra steps aren't much effort and the better design would probably payoff in the long run.
Apple Doc - View Controller Programmers Guide http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
advice on setting modal view controllers using delegates:
present modal view controller