UITableViewCell, which shows the subview to the touch and hides it with a second touch

I need to create a specific tableViewCell that shows a special subview on the first touch and hides it on the second touch . There are some shortcuts or buttons in this preview.

+4
source share
1 answer

In cellForRowAtIndexPath add the tag property to the subzone of the cell in question. Also set the subview hidden property to YES . Finally, set the selectionStyle cell to UITableViewCellSelectionStyleNone .

 if (thisIsTheIndexPathInQuestion) { CGRect theFrame = CGRectMake(...); // figure out the geometry first UIView *subview = [[UIView alloc] initWithFrame:theFrame]; // further customize your subview subview.tag = kSubViewTag; // define this elsewhere, any random integer will do subview.hidden = YES; cell.selectionStyle = UITableViewCellSelectionStyleNone; [cell.contentView addSubView:subview]; [subview release]; } 

Then simply respond to what you described in the corresponding delegate method of the UITableView:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (thisIsTheIndexPathInQuestion) { // you know how to check this UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; UIView *subview = [cell viewWithTag:kSubViewTag]; subview.hidden = !subview.hidden; // toggle if visible } } 

Make sure your custom cell has a different CellIdentifier and this will work.

+5
source

Source: https://habr.com/ru/post/1383307/


All Articles