I have a table view like a below picture:
I want to change check box and use mark check box when I select a table row in section Absence
I know that I should use this method didSelectRowAtIndexPath: “that when user select the row it should change the picture ”
but I don’t know how
would you please help me
Thanks in Advance!
here is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];
if (indexPath.section != 2) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.textLabel.text =contentForThisRow;
return cell;
}
else {
CheckBoxCompensationViewCell *cell = (CheckBoxCompensationViewCell*)[tableView
dequeueReusableCellWithIdentifier:@"CheckBoxCompensationViewCell"];
cell.imageView.image=[UIImage imageNamed:@"emptycheck-box.png"];
cell.checkBox.image = image;
if(indexPath.row == 0){
cell.compensationText.text =@"Red";
}
else if (indexPath.row == 1){
cell.compensationText.text =@"Green";
}else if(indexPath.row == 2){
cell.compensationText.text =@"Blue";
}
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// I don't know what should I have here , probably mark box image but I don't know how
}
note this is very basic, and wont deselect a cell, and you will need to check the state of the selected index path in cellForRowAtIndexPath: