ios - ARC 不允许将 Objective-C 指针转换为 'SEL'

标签 ios objective-c automatic-ref-counting pull-to-refresh

我正尝试在 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/

相关文章:

ios - 如何获取类方法的选择器?

ios - 如何在 ARC 下的 Instruments 中激活 Cycles 报告?

ios - 获取持续时间小于 10 秒的视频

ios - 如何在 UITextView 中的每一行添加无序列表或项目符号点

ios - PFQuery whereKey : containedIn: query doesn't works

objective-c - 如何在具有 NSAttributedStrings 的 NSComboBox 中添加自动完成功能

ios - 在 TouchDown 离开控件之后、TouchUp 之前检测手指

ios - 无法在 XCode 中存档 react-native 项目以使用 Pod 进行暂存配置

iPhone:在循环中创建 NSString 时出现巨大的内存峰值

objective-c - 新的自动引用计数机制如何工作?