Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch and Checkmarks in tableViews
    text
    copied!<p>I am trying to make a search bar in iOS and have made it to where it filters results and then when you click on it, it shows a checkmark. When I delete the search text, the check mark goes away and the full page of cells appears but the cell that I selected in the search is not selected with a check mark. Can someone please fix the code below to help me?</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableSet *selectedUsers = [NSMutableSet set]; static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; PFUser *user; if (self.userResults != nil) { user = [self.userResults objectAtIndex:indexPath.row]; } else { user = [self.allUsers objectAtIndex:indexPath.row]; } cell.textLabel.text = user.username; if ([selectedUsers containsObject:user]) { cell.accessoryType = UITableViewCellAccessoryNone; } else { cell.accessoryType = UITableViewCellAccessoryNone; } if ([selectedUsers containsObject:user]) { // user already selected } else { // select user [selectedUsers addObject:user]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryCheckmark; PFRelation *friendsRelation = [self.currentUser relationforKey:@"friendsRelation"]; PFUser *user = [self.allUsers objectAtIndex:indexPath.row]; [friendsRelation addObject:user]; [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (error) { NSLog(@"Error %@ %@", error, [error userInfo]); } }]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload