I’m trying to implement a searchDisplayController but I’ve a problem. Once I filtered the cell and when I selected the cell remaining I get a strange stack of text :
http://postimage.org/image/4fswe8t8n/
It’s like having all my cell in one.
So there’s my cellForRowAtIndexPath method :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MFriendCell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if(tableView == self.tableView) {
UILabel *nameLabel = (UILabel *)[cell viewWithTag:201];
nameLabel.text = [self.allItems objectAtIndex:indexPath.row];
}
else if(tableView == self.searchDisplayController.searchResultsTableView) {
UILabel *labelName = [ [UILabel alloc ] initWithFrame:CGRectMake(50, 0.0, 150.0, 43.0) ];
labelName.text = [self.searchResults objectAtIndex:indexPath.row];
[cell addSubview:labelName];
}
return cell;
}
And my filter :
- (void)filterContentForSearchText:(NSString*)searchText
scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"SELF contains[cd] %@",
searchText];
self.searchResults = [self.allItems filteredArrayUsingPredicate:resultPredicate];
}
if you need anything else just ask 🙂
You can make label in you tableView like this