从子视图中的另一个 viewController 中解除 ModalViewController
我有一个名为 A 的视图,使用 presentModalViewController
方法打开,在该视图中,我使用以下方法加载了辅助视图:
new_view = [[new_websongs alloc] initWithNibName:@"new_websongs" bundle:nil]; [mysubview addSubview:new_view.view];
好的,到这里就可以了,但是现在我需要关闭第一个视图“A”,调用一个方法 [selfmissModalViewControllerAnimated:YES]
如果第一个“A”viewController 来自辅助视图控制器(new_view)但不是工作!代码是:
self.Aviewcontroller = [[Aview alloc] init];
[Aviewcontroller dismissModalViewControllerAnimated:YES];
[Aviewcontroller release];
请帮助我!!!! 谢谢
I've got a view called A open with presentModalViewController
Method, inside this view I loaded secondary view using:
new_view = [[new_websongs alloc] initWithNibName:@"new_websongs" bundle:nil];
[mysubview addSubview:new_view.view];
ok, to here it's ok but now I need to dismiss the first view "A" calling a method [self dismissModalViewControllerAnimated:YES]
situated if first "A" viewController from secondary view controller (new_view) but not work! the code is:
self.Aviewcontroller = [[Aview alloc] init];
[Aviewcontroller dismissModalViewControllerAnimated:YES];
[Aviewcontroller release];
Please help ME!!!!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你尝试过
[self.parentViewController DismissModalViewControllerAnimated:YES];
Did u try
[self.parentViewController dismissModalViewControllerAnimated:YES];
你有一个逻辑问题。开始阅读 iOS 视图控制器编程指南
呈现模态视图控制器的视图控制器必须将其关闭,或者模态视图控制器必须自行将其关闭
You have a logical problem. Start reading View Controller Programming Guide for iOS
The view controller that present an modal view controller must dismiss it or the modal view controller must dismiss it self
完全同意其他答案;逻辑地思考视图控制器的顺序和类型的顺序。因此,请考虑哪些控制器以模态方式显示,哪些控制器通过导航控制器显示。
您当然可以设置多个视图控制器,并使用:
不动画,然后在需要时调用 say:
以在视图控制器堆栈中进一步显示指定的视图控制器。
希望这有助于思考您需要做什么?在单独的项目中考虑应用程序界面中视图控制器的顺序和类型通常是个好主意 - 您可以在设备本身上进行尝试。
Totally agree with other answers; think logically about the order of view controller order and type. So think about which controllers are shown modally, and those shown via a navigation controller.
You can of course set a number of view controllers with:
without animation, then when required call say:
to show a specified view controller further up your stack of view controllers.
Hope this helps think about what you need to do? It's often a good idea to think about the order and type of view controllers in your app's interface in a separate project - where you can try it out on the device itself.
试试这个应该可以
try this it should work
如果您从 UISplitViewController 呈现模式视图,则此方法有效。它还可以以多种其他方式应用...
首先,在 .h 文件中为 appDelegate 创建一个实例(
AppDelegate_iPad *appDelegate
),然后将其放入 viewDidLoad 或类似方法中:现在,呈现第一个模态视图,如下所示:
假设您有一个子视图,例如 UITableView,并且想要从 didSelectRowAtIndexPath 中关闭模态。要使用子视图关闭模式,您所要做的就是在子视图的 .h 中创建另一个 ipadDelegate 实例(如果需要),再次引用 [[UIApplication sharedApplication] delegate],然后关闭:
本质上,尽可能冗长如果您需要维护对 PresentingViewController 的持久引用,请使用您的 appDelegate 的控制器来呈现和关闭模式……因为上面的所有内容在我的情况下都不起作用。
如果您使用 ipadDelegate 进行演示,请确保检查 MainWindow_iPad.xib 中的演示模式。您的“过渡样式”应该是“垂直覆盖”,“演示文稿”应该是“当前上下文”,否则您的模式可能会出现在其他视图后面。
This works if you are presenting a modal view from a UISplitViewController. It can also be applied in so many other ways...
First, create an instance in your .h file for your appDelegate, (
AppDelegate_iPad *appDelegate
) then put this in your viewDidLoad or comparable method:Now, present the first modal view like this:
Say you have a subview, like a UITableView, and want to dismiss the modal from the didSelectRowAtIndexPath. All you have to do to dismiss your modal with a subview is create another ipadDelegate instance inside your subview's .h (if needed), reference the [[UIApplication sharedApplication] delegate] again, and dismiss:
Essentially, as long-winded as it may be, use your appDelegate's controller to present and dismiss the the modal if you need to maintain a persistent reference to the presentingViewController...because all the things above just don't work in my case.
If you're presenting with your ipadDelegate, make sure you check the mode of presentation in your MainWindow_iPad.xib. Your "Transition Style" should be "Cover Vertical" and "Presentation" should be "Current Context" or your modal may present behind other views.