在 swift 中的条件 segue 中获取 NSInternalInconsistencyException
Getting NSInternalInconsistencyException in conditional segue in swift
我正在 UIButton Click 事件侦听器中执行条件转场。我的 segue 是在带有 "pathanToDekhun" 标识符的情节提要中的 "pathanViewController" 和 "dekhunViewController" 之间绘制的。但是我收到 NsInternalInconsistencyException 作为
*** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit_Sim/UIKit-3318.16.14/Keyboard/UIKeyboardTaskQueue.m:374
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
单击按钮后,我执行了外部 api 调用,在成功 return 消息后,我使用 performSegueWithIdentifier 调用了 segue。但是实际上从未发生过这种情况。下面是我在 pathanViewController 中的代码部分。请让我知道我做错了什么。
@IBAction func sendBtnListener(sender: AnyObject) {
if !self.commentSection.text.isEmpty {
var submitVoganti = DataSerialization(brandName: self.brandName!, rating: Int(self.sliderStatus.value*5), commentText: self.commentSection.text, anonymous: switchBox.on ? true : false)
var dataSet = DataSet()
dataSet.postComment(submitVoganti.toJson(),{
(id) in
self.performSegueWithIdentifier("pathanToDekhun", sender: self)
println(id)
})
} else{
println("Comment field should not be empty")
}
}
//Check whether a segue should be triggered or not
override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
if identifier == "pathanToDekhun" {
return false
}
// by default, transition
return true
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var dekhunScene = segue.destinationViewController as ThirdViewController
dekhunScene.keyword = self.brandName
}
我做错的是我的 performSegueWithIdentifier 没有在主队列中调用。这就是它抛出异常的原因。我现在正在做的只是如下编辑我的代码 -
dataSet.postComment(submitVoganti.toJson(),{
(id) in
dispatch_async(dispatch_get_main_queue()){
self.performSegueWithIdentifier("pathanToDekhun", sender: self)
}
println(id)
})
并注释掉 "override func shouldPerformSegueWithIdentifier" 函数。就是这样。
我正在 UIButton Click 事件侦听器中执行条件转场。我的 segue 是在带有 "pathanToDekhun" 标识符的情节提要中的 "pathanViewController" 和 "dekhunViewController" 之间绘制的。但是我收到 NsInternalInconsistencyException 作为
*** Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit_Sim/UIKit-3318.16.14/Keyboard/UIKeyboardTaskQueue.m:374
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.'
单击按钮后,我执行了外部 api 调用,在成功 return 消息后,我使用 performSegueWithIdentifier 调用了 segue。但是实际上从未发生过这种情况。下面是我在 pathanViewController 中的代码部分。请让我知道我做错了什么。
@IBAction func sendBtnListener(sender: AnyObject) {
if !self.commentSection.text.isEmpty {
var submitVoganti = DataSerialization(brandName: self.brandName!, rating: Int(self.sliderStatus.value*5), commentText: self.commentSection.text, anonymous: switchBox.on ? true : false)
var dataSet = DataSet()
dataSet.postComment(submitVoganti.toJson(),{
(id) in
self.performSegueWithIdentifier("pathanToDekhun", sender: self)
println(id)
})
} else{
println("Comment field should not be empty")
}
}
//Check whether a segue should be triggered or not
override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
if identifier == "pathanToDekhun" {
return false
}
// by default, transition
return true
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var dekhunScene = segue.destinationViewController as ThirdViewController
dekhunScene.keyword = self.brandName
}
我做错的是我的 performSegueWithIdentifier 没有在主队列中调用。这就是它抛出异常的原因。我现在正在做的只是如下编辑我的代码 -
dataSet.postComment(submitVoganti.toJson(),{
(id) in
dispatch_async(dispatch_get_main_queue()){
self.performSegueWithIdentifier("pathanToDekhun", sender: self)
}
println(id)
})
并注释掉 "override func shouldPerformSegueWithIdentifier" 函数。就是这样。