ARC 不允许将 Objective-C 指针转换为 'SEL'
Cast of an Objective-C pointer to 'SEL' is disallowed with ARC
我正在尝试为 iOS 中的 UITableView 实现下拉刷新。实施即将完成,只是我无法正确执行刷新操作所需的操作。
[self.refreshControl addTarget:self
action:(SEL)[self performSelector:@selector(fetchPhotoListWith:Using:)
withObject:@"https://api.instagram.com/v1/users/self/feed?access_token="
withObject:@"<my Instagram ID>"]
forControlEvents:UIControlEventValueChanged];
以上代码(在 viewDidLoad
中启动)给出了以下错误:
Cast of an Objective-C pointer to 'SEL' is disallowed with ARC
如果我去掉前面的(SEL)
铸造,这次我得到以下错误:
Implicit conversion of an Objective-C pointer to 'SEL' is disallowed with ARC
还有一个警告:
Incompatible pointer types sending 'id' to parameter f type 'SEL'
如何在能够使用两个参数调用我的方法的同时很好地使用 ARC?
这不是 target/action 的工作方式,您需要向它传递一个选择器,该选择器是它在文档中列出的一种形式。
你应该这样做:
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
然后让刷新方法调用您的方法来刷新该数据:
- (void)refresh {
[self fetchPhotoListWith:@"https://api.instagram.com/v1/users/self/feed?access_token="
using:@"<My Instagram API Token>"];
}
我正在尝试为 iOS 中的 UITableView 实现下拉刷新。实施即将完成,只是我无法正确执行刷新操作所需的操作。
[self.refreshControl addTarget:self
action:(SEL)[self performSelector:@selector(fetchPhotoListWith:Using:)
withObject:@"https://api.instagram.com/v1/users/self/feed?access_token="
withObject:@"<my Instagram ID>"]
forControlEvents:UIControlEventValueChanged];
以上代码(在 viewDidLoad
中启动)给出了以下错误:
Cast of an Objective-C pointer to 'SEL' is disallowed with ARC
如果我去掉前面的(SEL)
铸造,这次我得到以下错误:
Implicit conversion of an Objective-C pointer to 'SEL' is disallowed with ARC
还有一个警告:
Incompatible pointer types sending 'id' to parameter f type 'SEL'
如何在能够使用两个参数调用我的方法的同时很好地使用 ARC?
这不是 target/action 的工作方式,您需要向它传递一个选择器,该选择器是它在文档中列出的一种形式。
你应该这样做:
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
然后让刷新方法调用您的方法来刷新该数据:
- (void)refresh {
[self fetchPhotoListWith:@"https://api.instagram.com/v1/users/self/feed?access_token="
using:@"<My Instagram API Token>"];
}