我正尝试在 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 - ARC 不允许将 Objective-C 指针转换为 'SEL',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31216436/