在编辑模式下将UITableView与自定义UILabel分组 [英] Grouped UITableView with custom UILabels in Editing Mode

查看:54
本文介绍了在编辑模式下将UITableView与自定义UILabel分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分组的 UITableView ,用户可以在其中进入编辑模式并从表中删除行.该表的每个单元格都有两个 UILabels .当表格进入编辑模式时,自定义 UILabels 会向右推送并超出单元格的右边界.

I have a grouped UITableView where the user can enter editing mode and delete rows from the table. Each cell of the table has two UILabels. When the table enters into editing mode, the custom UILabels push to the right and go beyond the right border of the cell.

如果我使用标准的 cell.textLabel ,则标签会调整大小并停留在单元格的边界内.关于如何使用自定义 UILabels 的想法?

If I use the standard cell.textLabel, the label resizes and stays within the borders of the cell. Ideas about how to do this with the custom UILabels ?

推荐答案

您需要实现并使用以下两个UITableViewDelegate方法:

You need to implement and use these two UITableViewDelegate methods:

– tableView:willBeginEditingRowAtIndexPath:
– tableView:didEndEditingRowAtIndexPath:

在willBegin中,将UILabel框架设置为较小的宽度,并在didEndEditing上将其宽度设置为正常大小.

In willBegin, set your UILabel frame to have a smaller width and set the width to normal size on didEndEditing.

例如,如果您的UILabel超出边界50个像素,则您可以在方法中执行以下操作:

For example, if your UILabel is getting pushed 50 pixels out of the boundary, in your methods you do:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *thisCell = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];

    CGRect newFrame = thisCell.someUILabel.frame;

    newFrame.size.width -= 50;

    thisCell.someUILabel.frame = newFrame;
}

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *thisCell = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];

    CGRect newFrame = thisCell.someUILabel.frame;

    newFrame.size.width += 50;

    thisCell.someUILabel.frame = newFrame;
}

这篇关于在编辑模式下将UITableView与自定义UILabel分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆