我在textfield
内有一个tableviewcell
。我希望能够在文本字段中单击时显示UITableViewCellAccessoryCheckmark
。我怎么做 ?请帮忙。在此先感谢。
答案 0 :(得分:2)
- (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];
}
如果您使用的是Core Data,请使用fetchedresulcontroller。否则,请使用您的数组代替。
答案 1 :(得分:0)
使用
-(void)textFieldDidBeginEditing:(UITextField *)textField {
//get the cell and change its accessory type to check mark
}