2
votes

When I click this button -[Search], pop-up window appear .

If I write down search terms and click Search button, the data are filled in NSMutableArray.

This searchTable use 'custom cell'.

I can't combine 'custom cell' with The data in NSMutableArray.

get errors when reloaded 'searchTableView'.

How can I do? Please help me!~ Thank you~

[error]

2011-10-31 20:56:52.915 TheBE[1207:10403] abcd 2011-10-31 20:56:53.158 TheBE[1207:10403] * Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2011-10-31 20:56:53.159 TheBE[1207:10403] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' ** First throw call stack: (0x12a2052 0x1753d0a 0x124aa78 0xc712db 0x381ee3 0x382589 0x36ddfd 0x37c851 0x327322 0x12a3e72 0x29ba92d 0x29c4827 0x294afa7 0x294cea6 0x294c580 0x12769ce 0x120d670 0x11d94f6 0x11d8db4 0x11d8ccb 0x1fae879 0x1fae93e 0x2e8a9b 0x1d68 0x1cc5 0x1)



    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

         //****** custom cell *********/
        SearchContentCell *cell = (SearchContentCell *)[tableView dequeueReusableCellWithIdentifier:@"SearchCell"];

        [cell.contentLabel setLineBreakMode:UILineBreakModeWordWrap];
        [cell.contentLabel setMinimumFontSize:FONT_SIZE];
        [cell.contentLabel setNumberOfLines:0];
        [cell.contentLabel setFont:[UIFont systemFontOfSize:FONT_SIZE]];
        [cell.contentLabel setTag:1];     

        ....... 
        cell.verseLabel.text = @"Test2" ; 
        cell.contentLabel.text = @"test"; 
         .......

        return cell;   

    }
    -(void)mockSearch:(NSString*)searchString  
    {   
        [_data removeAllObjects];   
        [request setEntity:entityBible]; 
    //        
        //create predicate   
        NSString *wildcardedString = [NSString stringWithFormat:@"*%@*",searchString];  
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"content like %@", wildcardedString];

        [request setPredicate:predicate]; 

        NSError *error;
        NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
        if (mutableFetchResults == nil) {
            // Handle the error;
            NSLog(@"eerror");
        }

        _data = mutableFetchResults;

         [self.searchDisplayController.searchResultsTableView reloadData];  

    }
    -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{

        [self mockSearch:searchBar.text]; 

    }

I think error part :

[self.searchDisplayController.searchResultsTableView reloadData];

3
[This Stackoverfow link][1] helped me. Try it out. [1]: stackoverflow.com/q/8066668/751026thesummersign

3 Answers

3
votes

If that's really what your tableView:cellForRowAtIndexPath: method looks like, you're missing the part that allocates a new cell if dequeueReusableCellWithIdentifier: returns nil.

0
votes

I had the same error. I think it is because adjusting certain button properties means the view (apparently lazily created) needs to be set up, which means the table needs to be ready to go, and it isn't yet, perhaps because its datasource hasn't been connected or something. Try moving your button adjustment to later in the viewDidLoad method; that worked for me.

(See also UITableView getting Initialized in the middle of viewDidLoad?, wherein I posted the same answer.)

0
votes

custom cell in storyboard, not in "self.searchDisplayController.searchResultsTableView", so just change:

SearchContentCell *cell = (SearchContentCell *)[ -->tableView<-- dequeueReusableCellWithIdentifier:@"SearchCell"];

to

SearchContentCell *cell = (SearchContentCell *)[ -->self.tableView<--dequeueReusableCellWithIdentifier:@"SearchCell"];