Iphone, как мне исправить это предупреждение: '-respondsToSelector:' не найден в протоколе (ах) - PullRequest
4 голосов
/ 23 сентября 2010

Я получаю это предупреждение.

'- 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

Что мне нужно сделать, чтобы исправить ошибку?

Ответы [ 3 ]

12 голосов
/ 23 сентября 2010

Либо сделать SetsSectionController наследовать от NSObject:

@protocol SetsSectionController <NSObject>

... или приведение к id:

if ([(id) sectionController respondsTo...])
1 голос
/ 01 ноября 2013

Кому-то нужно,

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

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

Примечание: не забудьте об этом, #import <objc/message.h>

1 голос
/ 23 сентября 2010
if ([(NSObject *)sectionController respondsToSelector:
        @selector(tableView:titleForFooterInSection:)])
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...