0

我试图制作一个支持通过 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 (tableView==self.searchDisplayController.searchResultsTableView)

cell=[searchResults objectAtIndex:indexPath.row];

我的主要问题是,在这种情况下,我实际上如何允许在连接到 Internet 的可变数组中进行搜索?

4

0 回答 0