2011-09-05 62 views
0

我每次编译时都会收到此警告。警告: - 方法:在协议中找不到

警告: - 协议中找不到方法。

这是我在TableViewController.m文件中的代码。

@implementation TableViewController 

@synthesize delegate; 

- (NSArray *) placeId 
{ 
NSArray *places = [self.delegate classMethod: placeId]; 
    // WARNING SHOWS UP HERE. 
} 

//Here is my code in TableViewController.h file. 

@class TableViewController; 

@protocol TableViewControllerDelegate 
+ (NSArray *) classMethod: (NSString *) placeId; 
@end 

@interface TableViewController : UITableViewController 
{ 
id <TableViewControllerDelegate> delegate; 
} 

@property (assign) id <TableViewControllerDelegate> delegate; 
@end 

//My code in SubClass.h 

#import "TableViewController.h" 

@interface SubClass: NSObject <TableViewControllerDelegate> 

+ (NSArray *) classMethod: (NSString *) placeId; 

我能得到这个警告,因为它是一个+类方法:?我怎样才能解决这个问题?

任何帮助将不胜感激。

+0

你确定你需要方法'classMethod'是静态的吗? '+(NSArray *)classMethod:(NSString *)placeId;'=?>' - (NSArray *)classMethod:(NSString *)placeId;' – Nekto

回答

0

this计算器thread..your方法“类方法”是一个类的方法(多么讽刺),你不能使用类的一个对象调用它..

使用

[SubClass classMethod]; 

调用该函数..

+0

'[[[self delegate] class] classMethod]'。委托不一定是'SubClass'实例。 – albertamg

+0

...两个调用都可以工作。委托不一定是'SubClass'实例,但它几乎肯定会导入'SubClass.h',所以我认为这是一个有争议的问题。 – lxt

+0

@lxt如果委托不是'SubClass'的实例,那么您可能不想在'SubClass'上调用'classMethod',而是在委托的类上调用'classMethod'。 – albertamg

相关问题