删除时表视图单元重叠

时间:2011-04-22 12:54:38

标签: iphone cocoa-touch uitableview

我在表格视图单元格中有文本,显示在一行中。按下“编辑”按钮并按下负号以显示删除按钮。这会将单元格中的文本推入两行,导致单元格重叠。我的细胞也有字幕。我在其他单元格中有两行文本,删除时被截断。我设置cell.textLabel.numberOfLines = 2来执行此操作,这不是问题。

如何在删除按钮出现时将单行文本显示在一行中?将两行文本保持在单元格中。

任何帮助将不胜感激!感谢

1 个答案:

答案 0 :(得分:0)

我设法找到解决方案......它没有我想象的那么复杂

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {

    Favorites *favorite = [fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = favorite.name;
    NSLog(@"%d",[favorite.name length]);
    NSLog(@"%@",favorite.name);
    if ([favorite.name length] <= 34) {
       cell.textLabel.numberOfLines = 1;
       NSLog(@"no. of lines = 1");
    }else{
       cell.textLabel.numberOfLines = 2;
       NSLog(@"no. of lines = 2");
}
cell.detailTextLabel.text = favorite.subTopic;}

configureCell

中调用了- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法

基本上我正在检查字符串中的字符数。我发现这个神奇的数字是34个字符,所以一切都适合。

相关问题