从子视图中的另一个 viewController 中解除 ModalViewController

发布于 2024-11-04 16:31:19 字数 548 浏览 2 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

情仇皆在手 2024-11-11 16:31:19

你尝试过[self.parentViewController DismissModalViewControllerAnimated:YES];

Did u try [self.parentViewController dismissModalViewControllerAnimated:YES];

意中人 2024-11-11 16:31:19

你有一个逻辑问题。开始阅读 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

蓝天白云 2024-11-11 16:31:19

完全同意其他答案;逻辑地思考视图控制器的顺序和类型的顺序。因此,请考虑哪些控制器以模态方式显示,哪些控制器通过导航控制器显示。

您当然可以设置多个视图控制器,并使用:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

动画,然后在需要时调用 say:

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

以在视图控制器堆栈中进一步显示指定的视图控制器。

希望这有助于思考您需要做什么?在单独的项目中考虑应用程序界面中视图控制器的顺序和类型通常是个好主意 - 您可以在设备本身上进行尝试。

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:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

without animation, then when required call say:

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

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.

你的他你的她 2024-11-11 16:31:19

试试这个应该可以

    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

try this it should work

    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
滥情空心 2024-11-11 16:31:19

如果您从 UISplitViewController 呈现模式视图,则此方法有效。它还可以以多种其他方式应用...

首先,在 .h 文件中为 appDelegate 创建一个实例(AppDelegate_iPad *appDelegate),然后将其放入 viewDidLoad 或类似方法中:

ipadDelegate = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];

现在,呈现第一个模态视图,如下所示:

    YOURVC *vc = [[YOURVC alloc] initWithNibName:@"YOURVC" bundle:nil];
    [ipadDelegate.splitViewController presentModalViewController:vc animated:YES];
    [vc release];

假设您有一个子视图,例如 UITableView,并且想要从 didSelectRowAtIndexPath 中关闭模态。要使用子视图关闭模式,您所要做的就是在子视图的 .h 中创建另一个 ipadDelegate 实例(如果需要),再次引用 [[UIApplication sharedApplication] delegate],然后关闭:

[ipadAppDelegate.splitViewController dismissModalViewControllerAnimated:YES];

本质上,尽可能冗长如果您需要维护对 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:

ipadDelegate = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];

Now, present the first modal view like this:

    YOURVC *vc = [[YOURVC alloc] initWithNibName:@"YOURVC" bundle:nil];
    [ipadDelegate.splitViewController presentModalViewController:vc animated:YES];
    [vc release];

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:

[ipadAppDelegate.splitViewController dismissModalViewControllerAnimated:YES];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文