gpt4 book ai didi

ios - type() 不符合协议(protocol)anyobject

转载 作者:搜寻专家 更新时间:2023-11-01 06:08:12 25 4
gpt4 key购买 nike

我试图在离开 View Controller 之前确认提交:

但是我收到了这个错误:

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() 返回什么,因为您没有提供它。从错误中,我假设它返回 () (即“void”或“nothing”)。您不能将其结果分配给属性。

我假设您真正想要做的是在按下按钮时调用此函数。这不是目标/操作按钮的工作方式。请参阅 Concepts in Objective-C Programming 中的 Target-Action .您需要将 target 设置为您希望消息发送到的对象,并将 action 设置为您要发送的选择器。

关于ios - type() 不符合协议(protocol)anyobject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31811426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com