获取错误类不是密钥值的密钥值编码兼容

时间:2013-03-16 13:07:28

标签: iphone ios uisearchbar

我在TableView中实现了SearchBar。但是当我尝试在SearchBar中输入文本时,它会显示错误。

这是我的NSObject类代码.h文件:

#import <Foundation/Foundation.h>

@interface ChannelList : NSObject
{

    NSString *channelLink;
    NSString *channelName;
    NSString *channelType;
    NSString *channelLogo;
}

@property (nonatomic, copy) NSString *channelName;
@property (nonatomic, copy) NSString *channelType;
@property (nonatomic, copy) NSString *channelLogo;

@property (nonatomic, copy) NSString *channelLink;

+ (id)channelLink:(NSString*)channelLink channelName:(NSString*)achannelName channelType:(NSString*)achannelType channelLogo:(NSString*)achannelLogo;

@end

和.m文件:

#import "ChannelList.h"

@implementation ChannelList

@synthesize channelLogo,channelName,channelType,channelLink;

+ (id)channelLink:(NSString*)channelLink channelName:(NSString*)achannelName channelType:(NSString*)achannelType channelLogo:(NSString*)achannelLogo{

    ChannelList *ChannelList = [[self alloc] init];

    [ChannelList setChannelLink:channelLink];
    [ChannelList setChannelName:achannelName];
    [ChannelList setChannelType:achannelType];
    [ChannelList setChannelLogo:achannelLogo];

    return ChannelList;
}
@end

使用此数组填充我的表格视图

channelAllData = [NSArray arrayWithObjects:
                      [ChannelList channelLink:@"http://cdn.m.yuppcdn.net/liveorigin/smil:ndtvhindi_iphone.smil/playlist.m3u8" channelName:@"NDTV" channelType:@"NEWS" channelLogo:@"ndtv.png"],[ChannelList channelLink:@"http://cdn.m.yuppcdn.net/liveorigin/smil:aajtak_iphone.smil/playlist.m3u8" channelName:@"Aaj_Tak" channelType:@"NEWS" channelLogo:@"Aaj_Tak"],[ChannelList channelLink:@"http://cdn.m.yupptv.tv/liveorigin/smil:indiatv.smil/playlist.m3u8" channelName:@"India_tv" channelType:@"NEWS" channelLogo:@"India_tv_logo.gif"],[ChannelList channelLink:@"http://cdn.m.yuppcdn.net/liveorigin/smil:headlinetoday_iphone.smil/playlist.m3u8" channelName:@"HeadlinesToday" channelType:@"NEWS" channelLogo:@"HeadlinesToday.png"],nil];


    searchedData = [NSMutableArray arrayWithCapacity:[channelAllData count]];

此处searchData是我的SearchBar的搜索结果。

在这里,我填充了我的搜索数据,并在标题中提到了错误。

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    // remove all data that belongs to previous search
    [searchedData removeAllObjects];
    if([searchText isEqualToString:@""]||searchText==nil){
        [self.tableView reloadData];
        return;
    }
    [self filterContentForSearchText:searchText];

   // NSLog(@"%i",searchedData.count);
    [self.tableView reloadData];

}

- (void)filterContentForSearchText:(NSString*)asearchText
{
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",asearchText];
    NSLog(@"predicate %@",predicate);
    NSArray *tempArray = [channelAllData filteredArrayUsingPredicate:predicate];
    searchedData = [NSMutableArray arrayWithArray:tempArray];
}

1 个答案:

答案 0 :(得分:3)

在谓词中,您使用的是self.name,而您的类中没有声明name属性。你的意思是self.channelName吗?