Evan Johnson Evan Johnson - 1 year ago 125
iOS Question

iOS editing tableview hide subview in cell

I have a question regarding editing a UITableView. I want to know how to hide a subview when the deletion control is tapped and the the delete button appears. I've figured out how to hide the subview when the delete button is tapped, but that is too late. I used the following code to accomplish that:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
exerciseDate = (UILabel *)[cell viewWithTag:8989];
exerciseDate.hidden = YES;

As you can see in the screenshots below, the text 'Today' and 'Yesterday' is the subview of each cell. I want to hide this subview when the deletion control (the red round button to the left) is tapped and the delete button appears (screen shot 2). Do I need to set up a listener for the deletion control? If so, how would I do that?

Thank you in advance!

Screen Shot 1
Screen Shot 2

Answer Source

There's the answer to your question, and then there's what I think you really want to do but don't know it.

What you asked for: Subclass UITableViewCell and use the new one. Implement this on the class:

- (void) setEditing:(BOOL)editing animated:(BOOL)animated 
    [super setEditing:editing animated:animated];
    UILabel *label = (UILabel *)[self viewWithTag:3]; // whatever you tag the label as
    label.hidden = editing;

What I would suggest you do though is the following: If you created the cell in InterfaceBuilder (or Xcode4's version thereof), change the label on the right's resizing behavior. You want it anchored to the right (default is left). Then when the cell resizes the content to fit the default button on there, it will push the "Today" label over to the left.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download