如何解决在编辑模式下将UITableView与自定义UILabel分组
|| 我有一个分组的“ 0”,用户可以在其中进入编辑模式并从表中删除行。表格的每个单元格都有两个“ 1”。当表格进入编辑模式时,自定义UILabels
向右推动并超出单元格的右边界。
如果我使用标准cell.textLabel
,标签会调整大小并停留在单元格的边界内。关于如何使用自定义UILabels
的想法?
解决方法
您需要实现和使用以下两个UITableViewDelegate方法:
– tableView:willBeginEditingRowAtIndexPath:
– tableView:didEndEditingRowAtIndexPath:
在willBegin中,将UILabel框架设置为较小的宽度,并在didEndEditing上将其宽度设置为正常大小。
例如,如果您的UILabel超出边界50个像素,则在您的方法中执行以下操作:
- (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;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。