【问题标题】:Iphone, how do I fix this warning: '-respondsToSelector:' not found in protocol(s)Iphone,我该如何解决这个警告:'-respondsToSelector:' not found in protocol(s)
【发布时间】:2010-09-23 11:44:03
【问题描述】:

我收到了这个警告。

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

这是我的完整 h 文件。

#import <UIKit/UIKit.h>


@interface SettingsTableViewController : UITableViewController {
    NSArray *sectionControllers;

}

@end

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

【问题讨论】:

    标签: iphone xcode uitableview iphone-sdk-3.0


    【解决方案1】:

    要么让SetsSectionController 继承自NSObject

    @protocol SetsSectionController <NSObject>
    

    ...或转换为id:

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

    【讨论】:

      【解决方案2】:
      if ([(NSObject *)sectionController respondsToSelector:
              @selector(tableView:titleForFooterInSection:)])
      

      【讨论】:

        【解决方案3】:

        有人需要,

        SEL selector = NSSelectorFromString(@"tableView:titleForFooterInSection:");
        
        if([sectionController respondsToSelector:selector]) {
            objc_msgSend(sectionController, selector, tableview, section);
        }
        

        注意:不要忘记这一点,#import &lt;objc/message.h&gt;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-05-23
          • 2021-07-01
          • 2015-09-11
          • 2022-12-09
          • 1970-01-01
          相关资源
          最近更新 更多