我试图创建一个支持搜索RSS源的RSS应用程序。我的代码在Github上(链接:https://github.com/sammy0025/SST-Announcements)。我试图应用搜索功能的视图控制器是SSTAMasterViewController。
在调整并结合Ray Wenderlich的“如何制作简单的RSS阅读器教程”和“如何将搜索添加到表格视图”中的代码之后,每当我尝试键入搜索栏时,我都会遇到这样的错误:
2013-06-02 16:53:44.764 SBlog Feed[2940:c07] -[RSSEntry setTableViewStyle:]: unrecognized selector sent to instance 0x7571930
2013-06-02 16:53:44.765 SBlog Feed[2940:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RSSEntry setTableViewStyle:]: unrecognized selector sent to instance 0x7571930'
我怀疑它可能与我的filterContentForSearchText方法有关:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[self.searchResults removeAllObjects];
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF.articleTitle contains[c] %@",
searchText];
searchResults = [NSMutableArray arrayWithArray:[_allEntries filteredArrayUsingPredicate:resultPredicate]];
}
或我的cellForRowAtIndexPath方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell"; //Declare Cell Indent
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row]; //Makes individual entities for the entry
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
cell.textLabel.text = entry.articleTitle;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", articleDateString];
if (tableView==self.searchDisplayController.searchResultsTableView)
{
cell=[searchResults objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.text=entry.articleTitle;
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@",articleDateString];
}
return cell;
}
尽管如此,我强烈怀疑这些代码:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self filterContentForSearchText:searchString scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
和if if(tableView == self.searchDisplayController.searchResultsTableView)
cell=[searchResults objectAtIndex:indexPath.row];
我的主要问题是如何在这种情况下实际允许在互联网上挂钩的Mutable Array中进行搜索?