I upgraded my Swift app to Xcode 7 / Swift 2.0 and now suddenly certain segues in my app no longer work.
我将我的Swift应用程序升级到Xcode 7 / Swift 2.0,现在我的应用程序突然发现某些segues不再有效。
I have a segue popping up a "Check In" modal and it works perfectly, but then I have another segue popping up a "Check Out" modal that's near identical and it doesn't launch and the app is frozen.
我有一个segue弹出一个“Check In”模式并且它完美地工作,但是然后我有另一个segue弹出一个“Check Out”模式,它几乎相同并且它不会启动并且应用程序被冻结。
I re-created the segue from scratch, confirmed that it is identical to the "Check In" one, and it still doesn't work.
我从头开始重新创建了segue,确认它与“Check In”相同,但它仍然不起作用。
I also, instead, tried launching a blank view instead of my Check Out modal and it works fine.
相反,我也尝试启动空白视图而不是我的Check Out模式,它工作正常。
There are no errors, it just freezes, I did confirm that the "prepareForSegue" portion is being called correctly but the "viewDidLoad" portion of my modal is not being invoked.
没有错误,它只是冻结,我确实正确地调用了“prepareForSegue”部分但是我的模态的“viewDidLoad”部分没有被调用。
FYI, I have auto-layout turned off.
仅供参考,我已关闭自动布局。
5 个解决方案
#1
8
Does your "Check Out" modal have a UITextView? If it does, then there's a bug in Xcode 7 / iOS9 where you cannot launch a modal (or any root view) that contains a UITextView if you have set a default text value in storyboard.
你的“Check Out”模式是否有UITextView?如果确实如此,那么Xcode 7 / iOS9中存在一个错误,如果您在storyboard中设置了默认文本值,则无法启动包含UITextView的模式(或任何根视图)。
A work around is to make sure your UITextView in storyboard is either blank or has the default Lorem Ipsem value and instead, set the text programmatically in code on viewDidLoad.
解决方法是确保故事板中的UITextView为空白或具有默认的Lorem Ipsem值,而是在viewDidLoad上的代码中以编程方式设置文本。
Hopefully this bug will be fixed soon.
希望这个bug很快就会修复。
#2
1
I suspect there is infinite loop somewhere in you "Check Out" controller code. Try pausing app in debugger after presenting controller (when it freezes) and check stacktrace. If it doesn't help, try commenting-out code line-by-line in viewDidLoad
and viewWillAppear
to find line causing freeze.
我怀疑你的“Check Out”控制器代码中存在无限循环。在呈现控制器(冻结时)并检查堆栈跟踪后,尝试在调试器中暂停应用程序。如果它没有帮助,请尝试在viewDidLoad和viewWillAppear中逐行注释掉代码以查找导致冻结的行。
#3
1
I had this problem, try with this
我有这个问题,试试这个
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Storyboard Id")
self.presentViewController(viewController, animated: true, completion: nil)
})
You just have to give a storyboard id in your view and normally it's working.
您只需在视图中提供一个故事板ID,通常它正在工作。
#4
1
My app was working perfectly in iOS8. Its flow was:
我的应用程序在iOS8中完美运行。它的流程是:
VC: View Controller, NVC: Navigation View Controller, ER: Embedded root relationship between NVC and VC, PS: Push Segue, PG: Programmatic presentation
VC:View Controller,NVC:导航视图控制器,ER:NVC和VC之间的嵌入式根关系,PS:推送Segue,PG:程序化演示
NVC1---(ER)->VC1---(PS)->NVC2---(ER)->VC2 and so on.
NVC1 ---(ER) - > VC1 ---(PS) - > NVC2 ---(ER) - > VC2等。
The problem was that VC1-(PS)->NVC2 segue did not work, there was no freeze. vc1.prepareForSegue() was executed, but VC2 was not presented. I experimented and found that I did not have the UITextView problem mentioned here. By following the breadcrumbs outlined below, I got it work after hours of trying in the following way (code at the end): NVC1---(ER)->VC1---(PG)->VC2
问题是VC1-(PS) - > NVC2 segue不起作用,没有冻结。 vc1.prepareForSegue()已执行,但未显示VC2。我进行了实验,发现我没有提到这里提到的UITextView问题。按照下面列出的面包屑,我按照以下方式尝试了几个小时(最后的代码):NVC1 ---(ER) - > VC1 ---(PG) - > VC2
Here are the steps: As mentioned in Segue issue in iOS9, multiple NVCs are out of style (shame on Apple for suddenly ditching what is actually recommended in your online tutorial and making apps break!). So I modified NVC1---(ER)->VC1--(PS)->VC2 while VC2 was still embedded in NVC2. I got errors similar to the * post on view not in hierarchy. So I started doing the transition programmatically and after tackling present vs. push ViewController issue that results in "tried to push modally on active view controller"
message and then ViewController lifecycle issues that result in "Unbalanced calls to begin/end appearance transactions"
messages, I got the following code working. Based on this experience, I really think Apple should have left a working thing alone in Xcode7/iOS9 update.
以下是步骤:正如在iOS9中的Segue问题中所提到的,多个NVC都不合时宜(苹果公司因为突然放弃了在线教程中实际推荐的内容并使应用程序中断而感到羞耻!)。所以我修改了NVC1 ---(ER) - > VC1 - (PS) - > VC2,而VC2仍然嵌入在NVC2中。我在视图中没有类似于*帖子的错误,而不是在层次结构中。所以我开始以编程方式进行转换,并在解决当前与推送ViewController问题之后导致“试图在模式上推送活动视图控制器”消息,然后导致ViewController生命周期问题导致“不平衡调用开始/结束外观事务”消息,我得到以下代码工作。基于这种经验,我真的认为Apple应该在Xcode7 / iOS9更新中独自留下一个工作的东西。
//*********** VC1.swift. A translation of working code
class VC1:UIViewController{
private var viewController2:VC2?
private var showVC2: Bool = false
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if(showVC2) {
showVC2 = false
self.pushVC2()
}
}//viewWillAppear
private var info:String? // info from incoming user action.
@IBAction unwindToVC1FromUserAction(incomingSegue: UIStoryboardSegue?) {
// Do app-specific stuff to get info from incomingSegue and
// store in self.info variables.
let myboard: UIStoryBoard = self.storyboard!;
self.viewController2 = myboard.instantiateViewControllerWithIdentifier(
"VC2 Storyboard ID") as! VC2
self.prepareVC2() // Pass info to VC2.info, stuff you would have done in prepareForSegue
showVC2= true
} //unwind
private func prepareVC2() {
self.viewController2.info = self.info // etc..
}
private func pushVC2() {
self.navigationController!.pushViewController(viewController2!, animated:false)
}
} //class
#5
0
I had this, but it was none of the above. My segue call happened to be inside a block. When I moved the call to the main thread I saw that I had a 'NSUnknownKeyException' error in the new View Controller. Being inside the block seemed to prevent the error from registering in Xcode, so the app just appeared to hang without any errors.
我有这个,但它不是上述的。我的segue电话碰巧在一个街区内。当我将调用移动到主线程时,我看到我在新的View Controller中出现了“NSUnknownKeyException”错误。在块内部似乎可以防止错误在Xcode中注册,因此应用程序似乎挂起没有任何错误。
Once that was resolved the original code worked fine.
一旦解决了原始代码工作正常。
#1
8
Does your "Check Out" modal have a UITextView? If it does, then there's a bug in Xcode 7 / iOS9 where you cannot launch a modal (or any root view) that contains a UITextView if you have set a default text value in storyboard.
你的“Check Out”模式是否有UITextView?如果确实如此,那么Xcode 7 / iOS9中存在一个错误,如果您在storyboard中设置了默认文本值,则无法启动包含UITextView的模式(或任何根视图)。
A work around is to make sure your UITextView in storyboard is either blank or has the default Lorem Ipsem value and instead, set the text programmatically in code on viewDidLoad.
解决方法是确保故事板中的UITextView为空白或具有默认的Lorem Ipsem值,而是在viewDidLoad上的代码中以编程方式设置文本。
Hopefully this bug will be fixed soon.
希望这个bug很快就会修复。
#2
1
I suspect there is infinite loop somewhere in you "Check Out" controller code. Try pausing app in debugger after presenting controller (when it freezes) and check stacktrace. If it doesn't help, try commenting-out code line-by-line in viewDidLoad
and viewWillAppear
to find line causing freeze.
我怀疑你的“Check Out”控制器代码中存在无限循环。在呈现控制器(冻结时)并检查堆栈跟踪后,尝试在调试器中暂停应用程序。如果它没有帮助,请尝试在viewDidLoad和viewWillAppear中逐行注释掉代码以查找导致冻结的行。
#3
1
I had this problem, try with this
我有这个问题,试试这个
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Storyboard Id")
self.presentViewController(viewController, animated: true, completion: nil)
})
You just have to give a storyboard id in your view and normally it's working.
您只需在视图中提供一个故事板ID,通常它正在工作。
#4
1
My app was working perfectly in iOS8. Its flow was:
我的应用程序在iOS8中完美运行。它的流程是:
VC: View Controller, NVC: Navigation View Controller, ER: Embedded root relationship between NVC and VC, PS: Push Segue, PG: Programmatic presentation
VC:View Controller,NVC:导航视图控制器,ER:NVC和VC之间的嵌入式根关系,PS:推送Segue,PG:程序化演示
NVC1---(ER)->VC1---(PS)->NVC2---(ER)->VC2 and so on.
NVC1 ---(ER) - > VC1 ---(PS) - > NVC2 ---(ER) - > VC2等。
The problem was that VC1-(PS)->NVC2 segue did not work, there was no freeze. vc1.prepareForSegue() was executed, but VC2 was not presented. I experimented and found that I did not have the UITextView problem mentioned here. By following the breadcrumbs outlined below, I got it work after hours of trying in the following way (code at the end): NVC1---(ER)->VC1---(PG)->VC2
问题是VC1-(PS) - > NVC2 segue不起作用,没有冻结。 vc1.prepareForSegue()已执行,但未显示VC2。我进行了实验,发现我没有提到这里提到的UITextView问题。按照下面列出的面包屑,我按照以下方式尝试了几个小时(最后的代码):NVC1 ---(ER) - > VC1 ---(PG) - > VC2
Here are the steps: As mentioned in Segue issue in iOS9, multiple NVCs are out of style (shame on Apple for suddenly ditching what is actually recommended in your online tutorial and making apps break!). So I modified NVC1---(ER)->VC1--(PS)->VC2 while VC2 was still embedded in NVC2. I got errors similar to the * post on view not in hierarchy. So I started doing the transition programmatically and after tackling present vs. push ViewController issue that results in "tried to push modally on active view controller"
message and then ViewController lifecycle issues that result in "Unbalanced calls to begin/end appearance transactions"
messages, I got the following code working. Based on this experience, I really think Apple should have left a working thing alone in Xcode7/iOS9 update.
以下是步骤:正如在iOS9中的Segue问题中所提到的,多个NVC都不合时宜(苹果公司因为突然放弃了在线教程中实际推荐的内容并使应用程序中断而感到羞耻!)。所以我修改了NVC1 ---(ER) - > VC1 - (PS) - > VC2,而VC2仍然嵌入在NVC2中。我在视图中没有类似于*帖子的错误,而不是在层次结构中。所以我开始以编程方式进行转换,并在解决当前与推送ViewController问题之后导致“试图在模式上推送活动视图控制器”消息,然后导致ViewController生命周期问题导致“不平衡调用开始/结束外观事务”消息,我得到以下代码工作。基于这种经验,我真的认为Apple应该在Xcode7 / iOS9更新中独自留下一个工作的东西。
//*********** VC1.swift. A translation of working code
class VC1:UIViewController{
private var viewController2:VC2?
private var showVC2: Bool = false
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if(showVC2) {
showVC2 = false
self.pushVC2()
}
}//viewWillAppear
private var info:String? // info from incoming user action.
@IBAction unwindToVC1FromUserAction(incomingSegue: UIStoryboardSegue?) {
// Do app-specific stuff to get info from incomingSegue and
// store in self.info variables.
let myboard: UIStoryBoard = self.storyboard!;
self.viewController2 = myboard.instantiateViewControllerWithIdentifier(
"VC2 Storyboard ID") as! VC2
self.prepareVC2() // Pass info to VC2.info, stuff you would have done in prepareForSegue
showVC2= true
} //unwind
private func prepareVC2() {
self.viewController2.info = self.info // etc..
}
private func pushVC2() {
self.navigationController!.pushViewController(viewController2!, animated:false)
}
} //class
#5
0
I had this, but it was none of the above. My segue call happened to be inside a block. When I moved the call to the main thread I saw that I had a 'NSUnknownKeyException' error in the new View Controller. Being inside the block seemed to prevent the error from registering in Xcode, so the app just appeared to hang without any errors.
我有这个,但它不是上述的。我的segue电话碰巧在一个街区内。当我将调用移动到主线程时,我看到我在新的View Controller中出现了“NSUnknownKeyException”错误。在块内部似乎可以防止错误在Xcode中注册,因此应用程序似乎挂起没有任何错误。
Once that was resolved the original code worked fine.
一旦解决了原始代码工作正常。