在 XIB iOS 之间移动
我有一个基于视图的应用程序,包含三个 xib 文件,每个文件都有自己的视图控制器。我如何从一种更改为另一种?我使用它从 xib 1 移动到 xib 2,但是当我使用相同的代码从 xib 2 移动到 xib 1 时,我在 [selfpresentModal....] 行上得到 EXC_BAD_ACCESS。
MapView *controller = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
我怎样才能自由地从一个厦门国际机场转移到另一个厦门国际机场?
I have a view-based application with three xib files, each with its own view controllers. How do I change from one to another? I use this to move from xib 1 to xib 2, but when I use the same code to move from xib 2 to xib 1, i get a EXC_BAD_ACCESS on the [self presentModal....] line.
MapView *controller = [[MapView alloc] initWithNibName:@"MapView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
How can I freely move from one xib to another?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你想做的是呈现一个模态视图然后将其驳回,对吗?如果是这种情况,那么您将下面的代码放入您用来关闭它的方法中(例如 -(IBAction)dissmissModalView)
希望它有效。让我知道。
What I think you are trying to do is is present a modal view and then dismiss it, right? If that is the case then you put the code below in the method that you use to dismiss it(e.g. -(IBAction)dissmissModalView)
Hopefully that works. Let me know.
initWithNibName 并不是真正必要的......您可以将其更改为 nil。
所以,这里是正确的代码(没有动画):
当尝试使用present返回到视图1时,您不应该收到EXC_BAD_ACCESS。如果您无法解决它,只需使用它:
第二个视图控制器将消失,第一个视图控制器将再次可见。
initWithNibName isn't really necessary... you can change that to nil.
So, here is the correct code (without animation):
You should not be receiving EXC_BAD_ACCESS when trying to go back to view 1 using present. If you cannot resolve it, just use this instead:
The second view controller will disappear and the first view controller will be visible again.
请注意,像此处的其他答案一样呈现模式视图控制器将意味着您拥有不断累积的视图控制器堆栈。使用该应用程序足够长的时间就会崩溃。
相反,您可以从应用程序窗口中交换视图。以下是实现此目的的一种方法:
向应用程序委托添加一个数据成员以存储当前视图:
并在其中添加一条消息以交换 VC:
以及从一个屏幕交换到另一个屏幕:
Note that presenting modal view controllers like the other answers here will mean that you have an ever-accumulating stack of view controllers. Use the application long enough and it will crash.
Instead, you can swap out the view from the application's window. Here's one way of doing that:
Add a data member to your app delegate to store the current view:
and add a message there to swap VCs:
and to swap from one screen to another: