【发布时间】:2015-08-04 14:01:12
【问题描述】:
我正在尝试在离开视图控制器之前确认提交:
但是我收到了这个错误:
type () does not conform to protocol anyobject
这是出现错误的那一行:
self.navigationItem.backBarButtonItem?.target = self.validateBeforeBack("back", completion: { (bool) -> () in
self.navigationController?.popViewControllerAnimated(true)
})
UDATE:
所以解决方案是将 target 更改为 action 并将函数调用放入Selector()
那就是:
self.navigationItem.backBarButtonItem?.action = Selector(self.validateBeforeBack("back", completion: { (bool) -> () in
self.navigationController?.popViewControllerAnimated(true)
}))
【问题讨论】:
-
把你的委托方法@optional.
-
@ChetanPrajapati 我没有使用委托方法来解决这个问题,你能解释一下 func R U 的含义吗