我有一个关于编辑 UITableView 的问题。我想知道如何在点击删除控件并出现删除按钮时隐藏 subview 。我已经想出如何在点击删除按钮时隐藏 subview ,但为时已晚。我使用以下代码来实现:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
exerciseDate = (UILabel *)[cell viewWithTag:8989];
exerciseDate.hidden = YES;
正如您在下面的屏幕截图中看到的,文本“今天”和“昨天”是每个单元格的 subview 。我想在点击删除控件(左侧的红色圆形按钮)并出现删除按钮时隐藏此 subview (屏幕截图 2)。我是否需要为删除控件设置监听器?如果是这样,我该怎么做?
提前致谢!
最佳答案
有你问题的答案,还有我认为你真正想做但不知道的事情。
您要求的是:子类 UITableViewCell
并使用新的。在类上实现:
- (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;
}
不过,我建议您执行以下操作:
如果您在 InterfaceBuilder
(或其 Xcode4 版本)中创建单元格,请更改右侧的调整大小行为的 label
。您希望它固定在右侧(默认为左侧)。然后,当单元格调整
内容大小以适应那里的默认按钮时,它会将“今天”
标签推到左侧。
关于iphone - iOS编辑tableview在单元格中隐藏 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6405068/