0

I have the following setup in my app: I have a UITableView which has animated height change, when a cell is selected. 在单元格中,我有一个标签,当未选择单元格然后当它被选中时(单元格高度变大)我希望文本(UILabel)打开多行,基于文本。

这是我目前的代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {


    if(self.selectedIndex != nil && [self.selectedIndex isEqual:indexPath]) {
        return kCellHeight * 3.9;

    }

    return kCellHeight;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    ProductCell *cell = (ProductCell *) [tableView cellForRowAtIndexPath:indexPath];


    if (![indexPath isEqual:self.selectedIndex]) {

        cell.addButton.hidden = NO;

        cell.descLabel.numberOfLines = 0;
        cell.descLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [cell.descLabel sizeToFit];

        tableView.scrollEnabled = NO;

        self.selectedIndex = indexPath;

    }else {

        self.selectedIndex = nil;

        cell.descLabel.lineBreakMode = NSLineBreakByTruncatingTail;

        tableView.scrollEnabled = YES;


        cell.addButton.hidden = YES;

    }






    [tableView beginUpdates];


    [tableView endUpdates];


}

第一部分(当单元格被选中,展开并且高度变大时)文本适合我想要的,但第二部分(当单元格收缩,单元格高度恢复到正常高度时)文本没有适合新的高度并按我的意愿截断,它只是保持多行。我怎样才能解决这个问题?So when the cell is selected the text gets multilined and when the cell is deselected the text gets back to its normal truncated state?

4

1 回答 1

0

编辑:

覆盖 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

并在此函数中添加以下行 cell.descLabel.numberOfLines = 1;

于 2013-11-07T15:59:40.933 回答