Swift Delegate方法永远不会被调用

雷山·库玛拉辛格

我已经在模态中声明了我的协议,如下所示

protocol MapViewControllerDelegate : class {
    //func mapViewLocationSelected(sender:AnyObject, location:CLLocation, address:String)
    func didSelectMap(sender:AnyObject)
}

我也宣布了如下代表

weak var delegate : MapViewControllerDelegate?

然后我关闭屏幕并按如下所示调用委托方法

self.dismissViewControllerAnimated(true, completion: nil)
delegate?.didSelectMap(self)

在调用模型的视图控制器中,我有以下内容

声明模态VC如下

var mvController : MapViewController = MapViewController()

然后我将代表设置如下 viewDidLoad

mvController.delegate = self

然后我实现了委托方法

func didSelectMap(sender: AnyObject) {
    println("Came here")
}

但是我从来没有来过ddidSelectMap方法。我之前已经做过了,而且奏效了,我不知道出了什么问题。任何帮助,将不胜感激。

父级Viewcontroller pastebin.com/7z5vg6yJ

模型视图控制器pastebin.com/DwAa6erQ

可能是由于我使用的MapKit引起的问题吗?

提前致谢。

杰伊·马尤(Jay Mayu)

我的建议是在prepareForSegue方法中分配委托另外,请确保使用segue.destinationViewController来获取适当的VC。

我假设像下面这样。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showMapviewSegue"{
            mapVController = segue.destinationViewController as! MapViewController
            mapVController.delegate = self
        }
}

试试这个,它应该起作用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章