主/详细视图:从“添加”视图进入“详细”视图,反之亦然

时间:2018-12-31 09:28:07

标签: ios swift

这可能是一个非常简单的问题,但我找不到如何正确地(优雅地)实现这一目标的明确答案。

我有一个简单的项目列表(表格视图)(在下面的屏幕快照中称为模型)。添加新项目时,我有一个模态搜索显示Add view。 当点击Save时,此当前返回表格视图。 在列表(表视图)中,当点击某项时,它会显示detail view

行为举止

  1. 在添加新项目时点击save时,应该显示detail view,而不是返回列表
  2. edit中点击detail view时,它应显示add (edit actually) view,以供用户修改模型

这与本机iOS Contacts应用相同。

预先感谢您的帮助,对于问题的简单性表示抱歉!

The navigation storyboard


这是我尝试过的

在重复的Segue上使用自定义Segue以显示详细信息

class FadeSegue: UIStoryboardSegue {

    override func perform() {

        guard let destinationView = self.destination.view else {
            // Fallback to no fading
            self.source.present(self.destination, animated: false, completion: nil)
            return
        }

        destinationView.alpha = 0
        self.source.view?.addSubview(destinationView)

        UIView.animate(withDuration: CATransaction.animationDuration(), animations: {
            destinationView.alpha = 1
        }, completion: { _ in
            destinationView.removeFromSuperview()
            self.source.present(self.destination, animated: false, completion: nil)
        })
    }
}

在新模型的Save中(在AddModelViewController中),我在列表(表)ViewController中将其称为:

self.dismiss(animated: false, completion: {
    self.performSegue(withIdentifier: "detailViewSegueAfterNewModel", sender: nil)
})

0 个答案:

没有答案
相关问题