简体   繁体   English

将视图控制器推入模态视图控制器视图

[英]Push view controller into modal view controller view

I'm trying to get working a simple operation. 我正在尝试简单的操作。 At least it seems simple. 至少看起来很简单。 Ok, what I'd like to do is to push a view (with push view controller) from a view that has been pushed with modal view controller. 好吧,我想做的是从一个用模态视图控制器推动的视图中推送视图(使用推视图控制器)。

View1 --(push using modal view controller)-->View2--(push using push view controller)--View3. View1 - (使用模态视图控制器推送) - > View2 - (使用推视图控制器推送) - View3。

Rigth now, i'm doing tests so i'm using a button to start the action. Rigth现在,我正在做测试,所以我正在使用一个按钮来启动动作。 Here's the code I use to push from View2 to view 3: 这是我用来从View2推送到视图3的代码:

//view2.h
UIToolbar *bar;
UIBarButtonItem *button;
UIToolbar *toolbar;

}

- (IBAction)demissModal:(id)sender;
- (IBAction)goView3:(id)sender;

@end

//view2.m
- (IBAction)goView3:(id)sender{

View3 *view_3 = [[View3 alloc] initWithNibName:@"View3" bundle:nil];
[self.navigationController pushViewController:view_3 animated:YES];

}

This is the same code I use to push View1 to View2, and it works. 这是我用来将View1推送到View2的相同代码,它可以工作。 But when pushing View2 to View3, it's not working. 但是当将View2推送到View3时,它无法正常工作。 Any idea of why happens that? 知道为什么会这样吗? Thanks! 谢谢!

View Controllers aren't actually 'modal' or 'push' view controllers. 视图控制器实际上不是“模态”或“推送”视图控制器。 Modal or Push describe a transition between view controllers (called segues if you're using storyboards). Modal或Push描述了视图控制器之间的转换(如果您使用的是故事板,则称为segues)。

What I think you're asking is how to modally present a view controller, and then push another controller. 我想你问的是如何以模态方式呈现视图控制器,然后推送另一个控制器。 The trick is when you modally present view controller #1, to actually present a navigation controller with its root view controller set as view controller #1. 技巧是当您以模态方式呈现视图控制器#1时,实际呈现导航控制器,其根视图控制器设置为视图控制器#1。

MyViewController *myViewController = [MyViewController alloc] init];
UINavigationController *navController = [UINavigationController alloc] initWithRootViewController:myViewController];

// Presuming a view controller is asking for the modal transition in the first place.
[self presentViewController:navController animated:YES completion:nil];
// Now in myViewController, call [self.navigationController pushViewController:secondViewController animated:YES];

This is what it looks like using storyboards: 这就像使用故事板一样: 在此输入图像描述

尝试这个:

[self.navigationController pushViewController:view_3 animated:YES];

First of all, I'm not sure where that gegant_se is coming from. 首先,我不确定gegant_se的来源。

Second of all, if you're pushing view2 from view1 the same way you're pushing view3 from view2, you're not using a modal. 其次,如果你从view1推送view2的方式与从view2推送view3的方式相同,那么你就不会使用模态。

Whenever you use a navigation controller to push a view controller, that view controller that was just pushed has a reference to the navigation controller, through the navigationController property. 每当您使用导航控制器推送视图控制器时,刚刚推送的视图控制器都会通过navigationController属性引用导航控制器。 Try this: 尝试这个:

[self.navigationController pushViewController:view_3 animated:YES];

try this code AlarmList is view name . 尝试此代码AlarmList是视图名称。

AlarmListScreen *loscr=[[AlarmListScreen alloc]initWithNibName:nil bundle:nil]; AlarmListScreen * loscr = [[AlarmListScreen alloc] initWithNibName:nil bundle:nil];

[self.navigationController pushViewController:loscr animated:YES]; [self.navigationController pushViewController:loscr animated:YES];

[loscr release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM