问题描述
我有一个第一个tableViewController,它在单击一个单元格时打开第二个tableViewcontroller。第二个视图控制器以模态方式显示(显示详细信息)并被解除:
I have a first tableViewController which opens up a second tableViewcontroller upon clicking a cell. The second view controller is presented modally (Show Detail segue) and is dismissed with:
self.dismissViewControllerAnimated(true, completion: {})
此时,第二个视图控制器滑开并显示其下方的第一个视图控制器。此时我想重新加载第一个视图控制器。我知道这可能需要使用委托功能,但我不知道如何继续。在此先感谢您的帮助!
At this point, the second view controller slides away and reveals the first view controller underneath it. At this point I would like to reload the first view controller. I understand that this may require use of delegate functions but am not sure how to proceed. Thanks in advance for your help!
推荐答案
我解决了它有点不同,因为我不希望这种依赖。
I solved it a bit differently since I don't want that dependancy.
当你以模态方式呈现控制器时,这种方法是有意的,因为呈现控制器在你解雇所呈现时不会重新加载。
And this approach is intended when you present a controller modally, since the presenting controller wont reload when you dismiss the presented.
无论如何解决方案!
而是你做一个单身人士(调解员)
Instead you make a Singleton (mediator)
protocol ModalTransitionListener {
func popoverDismissed()
}
class ModalTransitionMediator {
/* Singleton */
class var instance: ModalTransitionMediator {
struct Static {
static let instance: ModalTransitionMediator = ModalTransitionMediator()
}
return Static.instance
}
private var listener: ModalTransitionListener?
private init() {
}
func setListener(listener: ModalTransitionListener) {
self.listener = listener
}
func sendPopoverDismissed(modelChanged: Bool) {
listener?.popoverDismissed()
}
}
你有没有呈现控制器实现这样的协议:
Have you Presenting controller implement the protocol like this:
class PresentingController: ModalTransitionListener {
//other code
func viewDidLoad() {
ModalTransitionMediator.instance.setListener(self)
}
//required delegate func
func popoverDismissed() {
self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
yourTableViev.reloadData() (if you use tableview)
}
}
最后在viewDid / WillDisappear函数或自定义函数中的PresentedViewController中添加:
and finally in your PresentedViewController in your viewDid/WillDisappear func or custom func add:
ModalTransitionMediator.instance.sendPopoverDismissed(true)
这篇关于如何在Swift中解除模态显示的视图控制器后重新加载ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!