iPhone [self performeguewithidentifier ...]未显示新的视图控制器 [英] iPhone [self performseguewithidentifier... ] is not showing the new view controller

查看:52
本文介绍了iPhone [self performeguewithidentifier ...]未显示新的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都是stackoverflow,到处都是Google,我似乎无法弄清楚这一点.这是我的情况:

I have been all over stackoverflow and all over Google and I cannot seem to figure this one out. Here's my scenario:

我有我的应用程序的主屏幕",用户首先在该屏幕上决定要做什么.该应用程序基于通过导入" XML文件创建的CoreData数据库.用户可以选择在我的应用程序中打开附加到电子邮件的XML文件,这将自动触发我的主屏幕,以显示并运行文件的导入.

I have my app's "main screen" where the user first makes decisions about what they're going to do. The app works off of a CoreData database which is created by "importing" XML files. The user can choose to open an XML file attached to an email in my application, which automatically triggers my main screen to show up and run the import of the file.

我可以做到这一点,没有任何问题.在我的情节提要中,我从主屏幕到视图控制器都有一个名为ParseSegue的segue,它将处理解析并为用户提供一些状态信息.

I can get this far without any issues. In my storyboard, I have a segue called ParseSegue from my main screen to a view controller which will handle the parsing and give the user some status information.

通过电子邮件应用程序调用主屏幕时,主屏幕会自动调用

When the main screen is called via the email app, the main screen automatically calls

[self performSegueWithIdentifier:@"ParseSegue" sender:self];

然后我在prepareForSegue中检查此segue名称,它是有效名称.在这里,我将文件URL分配给解析器控制器,以便它可以解析正确的文件.

I then check for this segue name in prepareForSegue and it's a valid name. This is where I assign the file URL to the parser controller so that it can parse the correct file.

问题在于,segue从未真正发生过.prepareForSegue方法被调用,名称"ParseSegue"可以被检查并有效,但是segue本身根本不会发生.如果我在主屏幕上添加一个按钮,并告诉它在情节提要中执行segue,则它可以正常工作.但是以编程方式调用它似乎无济于事.

The problem is that the segue never actually happens. The prepareForSegue method gets called, the name "ParseSegue" can be checked against and is valid, but the segue itself simply does not happen. If I add a button to the main screen and tell it to perform the segue within the storyboard, it works fine. But calling it programmatically seems to do nothing.

推荐答案

事实证明,我完全在错误的地方看.我的问题是,在我的appDelegate(应用程序对传入的URL做出反应)中,我无意中创建了我的故事板和主视图控制器的新实例.这与已经处于活动状态并且可能不在屏幕上的屏幕不同.

It turns out that I was looking in the wrong place entirely. My problem was that in my appDelegate, where the app reacts to the incoming URL, I was inadvertently creating a new instance of my storyboard and my main view controller. This was different than the one which was already active and may or may not have been on the screen.

我创建的控制器从未真正显示过.我只注意到这是因为日志:

The controller I was creating was never actually shown. I only noticed this because the log:

NSLog(@"Source: %@", [segue.sourceViewController description]);

将为我的测试(按钮按下)和导入测试显示不同的内存地址.这使我相信,实际上,我正在使用故事板和应用程序的主视图控制器的两个不同实例.感谢Paul提出的记录目标和源控制器的建议.

would show different memory addresses for my test (the button push) and the import test. This led me to believe that I was, in fact, working with two different instances of the storyboard and the app's main view controller. Thanks to Paul for the suggestion of logging the destination and the source controllers.

这篇关于iPhone [self performeguewithidentifier ...]未显示新的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆