【发布时间】:2016-01-22 13:01:18
【问题描述】:
我有 2 个视图控制器 VCA 和 VCB。
从VCA 移动到VCB,有一些价值,工作正常
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("VCB") as! VCB
vc.entity = somevalue
self.navigationController?.pushViewController(vc, animated: true)
但是对于反向,我想在从VCB 上传某些数据后,从VCB 调用VCA 中的一个方法。然后刷新VCA 中的文本字段值。我可以在 VCA 中出现 viewwill 中的更新代码,但由于某种原因,我没有这样做,而是尝试实现委托。
我写了一些代码:
VCA:
class ProfileEditViewController:UIViewControoler, MobileVerifyDelegate{
override func viewDidLoad() {
super.viewDidLoad()
let mobileVC = MobileVerificationViewController()
mobileVC.delegate = self
}
//MARK: - Mobileverify Delegate method
func delegateMethod() {
print("a")
}
}
VCB:
protocol MobileVerifyDelegate{
func delegateMethod()
}
class MobileVerificationViewController: UIViewController{
var delegate: MobileVerifyDelegate! = nil
func certainFunction(){
//aftersuccessful upload
self?.delegate.delegateMethod()// code crashes
}
}
提前致谢
【问题讨论】: