nitin k m p
nitin k m p

Reputation: 329

display checkmark accessory type when clicking within textfield in tableview cell

I have a textfield within a tableviewcell. I want to be able to display a UITableViewCellAccessoryCheckmark on clicking within the textfield. How do i do that ? Please help. Thanks in Advance.

Upvotes: 0

Views: 1468

Answers (2)

Adarsh V C
Adarsh V C

Reputation: 2314


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = [[managedObject valueForKey:@"key"] description];

    if ([self.selectedCellValue isEqualToString:[[managedObject valueForKey:@"key"] description]]) {

        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];

    self.selectedCellValue = [[managedObject valueForKey:@"key"] description];

    [self.myTableView reloadData];

}

If you are using Core Data then go with fetchedresulcontroller. Otherwise use your array in place of that.

Upvotes: 2

Neelesh
Neelesh

Reputation: 3693

use the

-(void)textFieldDidBeginEditing:(UITextField *)textField {
//get the cell and change its accessory type to check mark 
}

Upvotes: 0

Related Questions