0

这一切可能是一个微不足道的问题,但我还没有找到解决方案。我正在使用 Swift 为 Iphone 制作一个应用程序。

我有一个带有一些字符串的表格视图,如果我按下一个按钮,我想直接导航回上一个视图。但是,我打电话后的代码

navigationController?.popViewControllerAnimated(true)

始终运行,但我希望当前活动停止并返回上一个视图。

代码如下所示:

    @IBAction func DeletePressed(sender: UIButton) {
    let deleteIndices = getIndexToDelete()
    navigationController?.popViewControllerAnimated(true)

    print("After navigationController")
    for index in deleteIndices{
        results?.ListResults[yearShownIndex].months[monthShownIndex].day[dayShownIndex].results.removeAtIndex(index)
    }
    if (results?.ListResults[yearShownIndex].months[monthShownIndex].day[dayShownIndex].results.count == 0){
        results?.ListResults[yearShownIndex].months[monthShownIndex].day.removeAtIndex(dayShownIndex)
    }
    if (results?.ListResults[yearShownIndex].months[monthShownIndex].day.count == 0){
        results?.ListResults[yearShownIndex].months.removeAtIndex(monthShownIndex)
    }
    if (results?.ListResults[yearShownIndex].months.count == 0){
        results?.ListResults.removeAtIndex(monthShownIndex)
    }
    loadView()
}

始终显示“导航控制器之后”。

在 android 中,您将通过创建意图来启动新活动以获得所需的行为,但它如何在 Iphone 上工作?

我的问题是我希望能够在navigationController.popViewControllerAnimated被调用时直接返回。这只是一个玩具示例,用于了解它是如何工作的,以便我以后可以在 if 子句中使用它。

4

2 回答 2

0

如果您不想在“打印(“导航控制器之后”)之后执行代码,则删除该代码

或者在调用 DeletePressed 时无法删除然后切换它

于 2016-03-26T12:04:28.943 回答
0

您可以在弹出视图控制器后简单地添加一条return语句:

@IBAction func DeletePressed(sender: UIButton) {
    let deleteIndices = getIndexToDelete()
    navigationController?.popViewControllerAnimated(true)
    return;
    [...]
于 2016-03-26T12:14:13.413 回答