0

I use a PFQueryTableViewController, and am having difficulties adding a SearchBar to the table view. The table view shows all the items from the specific Parse class, but I'm having issues getting the search functionality to work. Clicking search bar causes app to crash with error NSArray containsString unrecognized selector. My code for the search bar is below...as of now, I'm not even trying to do anything but log if it detects the text, because I don't know how to get the table to properly update. The PFQTVC automatically provides the tableview with data from its query, and I don't know how to update this

-(void) updateSearchResultsForSearchController:(UISearchController *)searchController {

        NSString *searchText = self.searchController.searchBar.text;
    NSLog(@"searchText %@", searchText);
       
            isFiltered = YES;
            
            searchResults = [[NSMutableArray alloc] init];
            if ( [[self.theObject valueForKey:@"NAME"] containsString:searchText]) {
                NSLog(@"FINE");
                
        }
        
        [self.tableView reloadData];
}

The rest of the code for the table view is below. I have some other things added for the cellForIndexPath code to show a checkmark on a row after a user selects it. What am I doing wrong for being able to search?

- (id)initWithCoder:(NSCoder *)aDecoder
{
    NSLog(@"initwithcoder");
    self = [super initWithCoder:aDecoder];
    if (self) {
        NSLog(@"self");
        // The className to query on
        self.parseClassName = @"SongsList";
        
        // Whether the built-in pull-to-refresh is enabled
        self.pullToRefreshEnabled = YES;
        
        // Whether the built-in pagination is enabled
        self.paginationEnabled = NO;
        
        // The number of objects to show per page
        self.objectsPerPage = 0;
        
        
    }
    return self;
}
- (PFQuery *)queryForTable {
    
    NSLog(@"QUERY");
    PFQuery *query = [PFQuery queryWithClassName:@"SongsList"];
    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.
    if (self.objects.count == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }
    NSLog(@"Count%lu", self.objects.count);
    [query orderByAscending:@"NAME"];
    query.limit = 2000;
    
   

    return query;
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.



// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
                        object:(PFObject *)object
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    self.theObject = object;
    
    RSSEntryDirectory *entry = [_allEntries objectAtIndex:indexPath.row];
    
    
    
    if ([self.chosen containsObject:object[@"NAME"]]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;

    }
    
    
    cell.textLabel.text = object[@"NAME"];
   
    if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
    {
        UIFont *cellFont = [UIFont fontWithName:@"ArialRoundedMTBold" size:38];
        cell.textLabel.font = cellFont;
        UIFont *cellFont2 = [UIFont fontWithName:@"ArialRoundedMTBold" size:24];
        cell.detailTextLabel.font = cellFont2;
    }
    else {
        UIFont *cellFont = [UIFont fontWithName:@"ArialRoundedMTBold" size:20];
        cell.textLabel.font = cellFont;
        UIFont *cellFont2 = [UIFont fontWithName:@"ArialRoundedMTBold" size:12];
        cell.detailTextLabel.font = cellFont2;
    }
    
    
    return cell;
}
user717452
  • 33
  • 14
  • 73
  • 149

0 Answers0