这一切可能是一个微不足道的问题,但我还没有找到解决方案。我正在使用 Swift 为 Iphone 制作一个应用程序。
我有一个带有一些字符串的表格 View ,如果我按下按钮,我想直接导航回上一个 View 。但是,我调用后的代码
navigationController?.popViewControllerAnimated(true)
始终运行,但我希望当前事件停止并返回到上一个 View 。
代码如下:
@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()
}
始终显示“After navigationController”。
在 Android 中,您可以通过创建意图来获得所需行为来启动新事件,但它在 Iphone 上如何工作?
我的问题是我希望能够在调用 navigationController.popViewControllerAnimated
时直接返回。这只是一个玩具示例,用于理解它是如何工作的,以便我稍后可以在 if 子句中使用它。
最佳答案
您可以在弹出 View Controller 后添加一个return
语句:
@IBAction func DeletePressed(sender: UIButton) {
let deleteIndices = getIndexToDelete()
navigationController?.popViewControllerAnimated(true)
return;
[...]
关于ios - 使用 NavigationViewController 更改 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36234869/