我想使用 push segue 来编辑一个“条目”,否则它是通过当前模态 segue 添加的。按下取消时,它不会使用正常的 dismissViewControllerAnimated 方法关闭。正因为如此,我不得不同时结合 popViewControllerAnimated 方法,以便根据他们在编辑条目或添加条目时是否单击取消,它会尝试两者。
两者都是通过 NSNotifcation 完成的,因为我需要将对象从最后一个 viewcontroller 带回第一个:
func cancel(notification: NSNotification){
println("Cancel Executed")
let userInfo:Dictionary<String,EntryItem!> = notification.userInfo as Dictionary<String,EntryItem!>
entry = userInfo["Object"]
tableView.reloadData()
self.navigationController?.popViewControllerAnimated(true)
dismissViewControllerAnimated(true, completion: nil)
dataModel.saveEntries()
}
这样做的问题是,如果我通过 segues 到达第三个视图控制器(在 5 个字符串中),我取消,它返回到条目屏幕,但是一个看起来很乱的导航栏取代了应该有什么。也没有显示标题。它有一个取消按钮,如果你按下它会导致崩溃。
这是它应该看起来的样子:
这是 popViewControllerAnimated 对它所做的。