iOS编辑tableview隐藏单元格中的子视图 [英] iOS editing tableview hide subview in cell
问题描述
我有一个关于编辑UITableView的问题。我想知道在点击删除控件并显示删除按钮时如何隐藏子视图。我已经想出了如何在点击删除按钮时隐藏子视图,但为时已晚。我使用以下代码来实现:
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;
正如您在下面的屏幕截图中看到的,文字'今天'和'昨天'是子视图每个细胞。我想隐藏这个子视图,当点击删除控件(左边的红色圆形按钮)并出现删除按钮时(屏幕截图2)。我是否需要为删除控件设置监听器?如果是这样,我该怎么做?
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?
提前谢谢你!
推荐答案
你的问题有答案,然后就是我认为你真的想要做的但是不知道。
There's the answer to your question, and then there's what I think you really want to do but don't know it.
你要求的内容:子类 UITableViewCell
并使用新的。在类上实现:
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;
}
我建议您做的如下:
如果你在 InterfaceBuilder
(或Xcode4的版本)中创建了单元格,在右边的调整大小行为上更改标签
。您希望它锚定在右侧(默认为左侧)。然后当单元格调整
内容以适应那里的默认按钮时,它将推送今天
标签在左边。
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.
这篇关于iOS编辑tableview隐藏单元格中的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!