【问题标题】:performSegue(withSender: sender:) does not work - no errors displayedperformSegue(withSender: sender:) 不起作用 - 不显示错误
【发布时间】: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()。

标签: swift segue swift3 xcode8


【解决方案1】:

好的,看来我已经解决了问题。我将主视图控制器嵌入到导航控制器中,现在一切都按预期工作。我之前尝试过同样的策略,但它一直在抛出错误。咕噜!

无论如何 - 谢谢大家的意见!

【讨论】:

    猜你喜欢
    • 2012-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多