2010-09-23 71 views
4

我收到此警告。Iphone,我该如何解决此警告:'-respondsToSelector:'找不到协议

“-respondsToSelector:”未在协议(多个)

它发生在通过“这里”下面标线找到。

- (NSString *)tableView:(UITableView *)tableView 
    titleForFooterInSection:(NSInteger)section { 

    id<SetsSectionController> sectionController = 
     [sectionControllers objectAtIndex:section]; 

    if ([sectionController respondsToSelector: 
      @selector(tableView:titleForFooterInSection:)]) { //HERE 

     return [sectionController tableView:tableView 
      titleForFooterInSection:section]; 

    } 
    return nil; 
} 

继承人我全h文件。

#import <UIKit/UIKit.h> 


@interface SettingsTableViewController : UITableViewController { 
    NSArray *sectionControllers; 

} 

@end 

我需要做什么来修复错误?

回答

12

无论是从制作NSObjectSetsSectionController继承:

@protocol SetsSectionController <NSObject> 

...或转换为id

if ([(id) sectionController respondsTo...]) 
1
if ([(NSObject *)sectionController respondsToSelector: 
     @selector(tableView:titleForFooterInSection:)]) 
1

有人需要,

SEL selector = NSSelectorFromString(@"tableView:titleForFooterInSection:"); 

if([sectionController respondsToSelector:selector]) { 
    objc_msgSend(sectionController, selector, tableview, section); 
} 

注:不要忘了这个,#import <objc/message.h>

相关问题