【发布时间】:2017-02-21 17:52:12
【问题描述】:
func checkForRecipes(noRecords: Bool) {
//segue to addNewRecipe page
if noRecords == true{
print("Can't Find any Recipes!")
self.performSegue(withIdentifier: "ToAddNewRecipeVC", sender: self)
}else{
print("error, noRecords not equal to zero")
}
我能够通过情节提要成功地进行转场,但希望根据代表返回的信息以编程方式进行。
在运行应用程序时,来自委托的信息已成功发送到函数“checkForRecipes”-即“noRecords”返回 TRUE,但由于某种原因,该函数中的以下代码行似乎没有执行(并且没有抛出错误):
self.performSegue(withIdentifier: "ToAddNewRecipeVC", sender: self)
应用程序启动但在主屏幕停止,而它应该转到“AddNewRecipe”视图控制器。
segue 本身的 segue ID 肯定是“ToAddNewRecipeVC”。我还尝试根据以下thread. 调度到主队列(无济于事)
我很难过 - 这里出了什么问题?
【问题讨论】:
-
不赞成使用屏幕截图的代码。将您的代码放入问题中。
-
@MwcsMac:我已将屏幕截图替换为一段代码。
-
在哪里调用 checkForRecipes()?
-
检查是否一切设置正确。你可以在这里使用我的回答stackoverflow.com/a/39930180/5327882 来解决一个非常相似的问题。最后只是代码中设置了一个错误的视图控制器
-
@Azimov:“noRecords”通过委托模式从另一个类发送到 checkForRecipes()。