IOS/X代码 : Calling NSFetchedResultsController Method in Other Class

标签 ios xcode nsfetchedresultscontroller

我在 TableView 中有一个 NSFetchedResultsController,我试图从另一个 Controller 调用它,但出现错误。

我将 tableVC 导入到 otherVC 中,但得到一个“No known class method for selector “fetchedResultsController”。有人能发现我做错了什么吗?谢谢。

code in tableVC.h
-(NSFetchedResultsController *)fetchedResultsController;
tableVC.m
-(NSFetchedResultsController *)fetchedResultsController {
    if (_fetchedResultsController==nil){
        NSFetchRequest *fetchRequest= [[NSFetchRequest alloc] init];
        ...
    return _fetchedResultsController;
}
otherVC.m
#import "tableVC.h"

  [tableVC fetchedResultsController];

感谢您的任何建议。

最佳答案

“No known class method for selector”表示您调用的是类方法,而不是实例方法。

类方法是用前导+号定义的,而你在tableVC.h中的fetchedResultsController是用前导-号定义的,表明它是一个实例方法。

解决方案是要么将 tableVC.h 中的 fetchedResultsController 的方法签名更改为类方法,要么将 otherVC.m 中的调用更改为使用 tableVC 的实例而不是类本身。

根据您的代码示例,fetchedResultsController 方法似乎被正确定义为实例方法,因此您需要在 otherVC 类中使用 tableVC 的实例。

关于IOS/X代码 : Calling NSFetchedResultsController Method in Other Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761759/

相关文章:

ios - iCloud 需要很长时间才能连接到本地商店,并且 iCloud 对上下文所做的更改会影响我的 fetchedResultsController

ios - NSTimeZone.localTimeZone().secondsFromGMT 崩溃

ios - 预期标识符

ios - 在 iOS Swift 2.1 中适合谷歌地图 View 以包含多边形的最佳方法?

iphone - NSFetchedResultsSectionInfo 对于它有多少个对象与自己不一致

ios - NSFetchedResultsController 尝试将第 1 行插入第 0 节,但在使用 userInfo (null) 更新后,第 0 节中只有 0 行

ios - 在 SLRequest 上设置超时策略?

ios - Xcode-如何为不同的构建配置设置不同的包标识符?

c# - 如何以编程方式在 Unity3D 中附加视频

swift - 运行脚本阶段错误 : framework is a directory