gpt4 book ai didi

ios - 将 void(^)(UIButton *_strong) 发送到不兼容类型 SEL 的参数时出错

转载 作者:行者123 更新时间:2023-11-28 18:57:11 39 4
gpt4 key购买 nike

我在这里尝试用功能 block 替换“@selector”。但是这样做会显示一条错误消息:

错误:发送 'void (^)(UIButton *__strong)' 到不兼容的参数 type 'SEL'

请指导如何直接放置功能 block ,而不是使用“@selector”。

[_contactPhoneButton addTarget:self
action:^(UIButton *sender) {
NSString *phoneNumber = [@"tel://" stringByAppendingString:sender.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
}

最佳答案

Block不能转化为SEL,它们是不同的类型。

  • SEL 是一个标识函数的名称,它被发送给对象。在运行时,对象使用SEL 来查找要执行的函数
  • Block是一些你可以执行的代码,它独立于Object。

如果你还想使用block,引用这个link .

关于ios - 将 void(^)(UIButton *_strong) 发送到不兼容类型 SEL 的参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31067333/

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