I want to change UIImagewhich is inside UITableViewCellwhen the user selects a row. That is now too much. I can do it in didSelectRowAtIndexjust fine. However, the problem is that I want the other cells (each to cellhave a standard image) to have a standard image again. (If the cells again have a standard image, the selected image should be “marked” (this means that the unlabeled image will be replaced by the marked image, for which I already have a code)
Pay attention to Checkboxwhich you know from HTML.
Here is my attempt:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView cellForRowAtIndexPath:indexPath];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[UIView animateWithDuration:2.0f animations:^{
} completion:^(BOOL finished) {
;
}];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
ALog(@"%i", cell.imageView.tag);
ALog(@"%i", [[[tableView cellForRowAtIndexPath:indexPath] imageView] tag]);
UIImageView *iconimgView = (UIImageView *)[[tableView cellForRowAtIndexPath:indexPath] viewWithTag:TAG_IMAGEMARKERCELL];
[iconimgView setImage:[UIImage imageNamed:@"circle-answer-marked.png"]];
}
Here is defined UIImageView:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[[cell textLabel] setNumberOfLines:0];
[[cell textLabel] setLineBreakMode:NSLineBreakByWordWrapping];
[[cell textLabel] setFont:[UIFont fontWithName:@"PTSans-Regular" size:33 / 2]];
[[cell textLabel] setTextColor:[self colorFromHexString:COLOR_DEFAULT_TEXT_COLOR]];
cell.indentationLevel = cell.indentationLevel + 2;
imgCell_Marker = [[UIImageView alloc]initWithFrame:CGRectMake(10, 22, 20, 20)];
imgCell_Marker.image=[UIImage imageNamed:@"circle-answer.png"];
imgCell_Marker.tag = TAG_IMAGEMARKERCELL;
ALog(@"%@", imgCell_Marker);
[cell.contentView addSubview:imgCell_Marker];
}
return cell;
}
, UIImageView tag, , didSelectRowAtIndexPath "0". ( tag)
.