type() 不符合协议anyobject
type () does not conform to protocol anyobject
我正在尝试在离开视图控制器之前确认提交:
但是我收到了这个错误:
type () does not conform to protocol anyobject
这里是出现错误的行:
self.navigationItem.backBarButtonItem?.target = self.validateBeforeBack("back", completion: { (bool) -> () in
self.navigationController?.popViewControllerAnimated(true)
})
更新 :
所以解决方案是将 target 更改为 action 并将函数调用放在 Selector()
中
即:
self.navigationItem.backBarButtonItem?.action = Selector(self.validateBeforeBack("back", completion: { (bool) -> () in
self.navigationController?.popViewControllerAnimated(true)
}))
不清楚 validateBeforeBack()
returns,因为您没有提供。根据错误,我假设它是 returns ()
(即 "void" 或 "nothing")。您不能将其结果分配给 属性.
我假设您真正想做的是在按下按钮时调用此函数。 target/action 按钮不是这样工作的。请参阅 Concepts in Objective-C Programming 中的 Target-Action
。您需要将 target
设置为您要将消息发送到的对象,并将 action
设置为您要发送的选择器。
popViewControllerAnimated(_:)
有一个 return 类型的 UIViewController?
,但是函数 validateBeforeBack(_:completion:)
的闭包参数有一个 Void
return 类型(你的 validateBeforeBack(_:completion:)
函数的实现,或者你传递给它的闭包,应该调整以考虑到这一点)
确保您的 validateBeforeBack(_:completion:)
函数实际上具有 return 类型(因为它是赋值中的值)
我正在尝试在离开视图控制器之前确认提交:
但是我收到了这个错误:
type () does not conform to protocol anyobject
这里是出现错误的行:
self.navigationItem.backBarButtonItem?.target = self.validateBeforeBack("back", completion: { (bool) -> () in
self.navigationController?.popViewControllerAnimated(true)
})
更新 :
所以解决方案是将 target 更改为 action 并将函数调用放在 Selector()
即:
self.navigationItem.backBarButtonItem?.action = Selector(self.validateBeforeBack("back", completion: { (bool) -> () in
self.navigationController?.popViewControllerAnimated(true)
}))
不清楚 validateBeforeBack()
returns,因为您没有提供。根据错误,我假设它是 returns ()
(即 "void" 或 "nothing")。您不能将其结果分配给 属性.
我假设您真正想做的是在按下按钮时调用此函数。 target/action 按钮不是这样工作的。请参阅 Concepts in Objective-C Programming 中的 Target-Action
。您需要将 target
设置为您要将消息发送到的对象,并将 action
设置为您要发送的选择器。
popViewControllerAnimated(_:)
有一个 return 类型的UIViewController?
,但是函数validateBeforeBack(_:completion:)
的闭包参数有一个Void
return 类型(你的validateBeforeBack(_:completion:)
函数的实现,或者你传递给它的闭包,应该调整以考虑到这一点)确保您的
validateBeforeBack(_:completion:)
函数实际上具有 return 类型(因为它是赋值中的值)