Iphone,我该如何修复此警告:' - responseToSelector:'在协议中找不到

时间:2010-09-23 11:44:03

标签: iphone xcode uitableview iphone-sdk-3.0

我收到了这个警告。

' - respondsToSelector:'找不到协议

它出现在下面标有“HERE”的行上。

- (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;
}

这是我的完整文件。

#import <UIKit/UIKit.h>


@interface SettingsTableViewController : UITableViewController {
    NSArray *sectionControllers;

}

@end

我需要做些什么才能解决错误?

3 个答案:

答案 0 :(得分:12)

SetsSectionController继承NSObject

@protocol SetsSectionController <NSObject>

...或投放到id

if ([(id) sectionController respondsTo...])

答案 1 :(得分:1)

if ([(NSObject *)sectionController respondsToSelector:
        @selector(tableView:titleForFooterInSection:)])

答案 2 :(得分:1)

有人需要,

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

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

注意:不要忘记这一点,#import <objc/message.h>

相关问题