开发者

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开发者_StackOverflow中文版)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!

iOS editing tableview hide subview in cell

iOS editing tableview hide subview in cell


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.


Set those Labels as properties like

@property (nonatomic, retain) UILabel *subViewLabel;

and then synthesize them.

When you want to hide them, follow the same procedure you are following, and use

self.subViewLabel.hidden = YES;


Are you using a custom cell? you can create the same effect by using UITableViewCellStyleValue1 (that controls itself your problem, and move automatically the label to left) and then by adding programmatically the UILabel to each cell in cellForRowAtIndexPath. If you are using UITableViewCellStyleSubtitle try to use UITableViewCellStyleValue1 and add the UIlabel on the bottom of the cell.textLabel property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜