Ios 将void(^)(UIButton*_strong)发送到不兼容类型SEL的参数时出错
我试图在这里用一个功能块替换“@selector”。但这样做会显示一个错误,即: 错误:向不兼容的参数发送“void(^)(UIButton*\uu strong)”类型“SEL” 请说明如何直接放置功能块,而不是使用“@selector”Ios 将void(^)(UIButton*_strong)发送到不兼容类型SEL的参数时出错,ios,objective-c,Ios,Objective C,我试图在这里用一个功能块替换“@selector”。但这样做会显示一个错误,即: 错误:向不兼容的参数发送“void(^)(UIButton*\uu strong)”类型“SEL” 请说明如何直接放置功能块,而不是使用“@selector” 不能将选择器替换为块,因为它们是不同的类型。但是,您可以考虑使用类似于ReactiveCocoa的方法来实现您想要的方法 不能用块替换选择器,因为它们是不同的类型。但是,您可以考虑使用类似于ReactiveCocoa的方法来实现您想要的方法 必须添加选择器,
不能将
选择器
替换为块
,因为它们是不同的类型。但是,您可以考虑使用类似于ReactiveCocoa
的方法来实现您想要的方法
不能用
块替换选择器
,因为它们是不同的类型。但是,您可以考虑使用类似于ReactiveCocoa
的方法来实现您想要的方法
必须添加选择器,而不是块:
[_contactPhoneButton addTarget:self
action: @selector(buttonTapped:)];
然后
- (void) buttonTapped: (uibutton*) sender
{
NSString *phoneNumber = [@"tel://" stringByAppendingString:sender.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
}
必须添加选择器,而不是块:
[_contactPhoneButton addTarget:self
action: @selector(buttonTapped:)];
然后
- (void) buttonTapped: (uibutton*) sender
{
NSString *phoneNumber = [@"tel://" stringByAppendingString:sender.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
}
试试这个:
[_contactPhoneButton addTarget:[^{
NSString *phoneNumber = [@"tel://" stringByAppendingString:sender.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} copy] action:@selector(invoke) forControlEvents:UIControlEventTouchUpInside];
试试这个:
[_contactPhoneButton addTarget:[^{
NSString *phoneNumber = [@"tel://" stringByAppendingString:sender.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} copy] action:@selector(invoke) forControlEvents:UIControlEventTouchUpInside];
无法将块转换为SEL。它们是不同的类型
- SEL是用于标识函数的名称,它被发送到对象。在运行时,对象使用SEL查找要执行的函数
- 块是可以执行的代码,它独立于对象
如果仍要使用块,请参阅此 块无法转换为SEL。它们是不同的类型
- SEL是用于标识函数的名称,它被发送到对象。在运行时,对象使用SEL查找要执行的函数
- 块是可以执行的代码,它独立于对象
如果仍要使用块,请参阅此