我在 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/