我有一个 UITable 我正在扩展以显示“更多信息”文本。我遇到的问题是文本可以有不同的大小,即 indexpath.section1 可能是 1200 高,而 index path.section2 是 300 高。
在重新使用单元格之前,我的代码工作正常,标签框的大小没有针对新标签进行调整。因此,尽管单元格的大小正确,但该单元格内的标签仍然具有原始大小的框架,所以如果它太小,文本会被截断,我会得到大量空白,如果它太大,那么除非我滚动到,否则我看不到文本场的中间。
我究竟做错了什么??请问有什么帮助吗??
这是我的代码:-
            static NSUInteger const k1 = 1;
            // Declare references to the subviews which will display the data.
            UILabel *lbl1 = nil;
            static NSString *kCellID = @"CellID";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
                if ((indexPath.section == 8) || (indexPath.section == 9) || (indexPath.section == 10) || (indexPath.section == 11) || (indexPath.section == 12) || (indexPath.section == 13) || (indexPath.section == 14)|| (indexPath.section == 15) || (indexPath.section == 16))
                {
                    lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 290, 200)];
                }
                else if ((indexPath.section == 4) || (indexPath.section == 5))
                {
                    lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 290, 1200)];
                }
                lbl1.font = [UIFont fontWithName:@"Trebuchet MS" size:12.0f];
                lbl1.tag = k1;
                lbl1.textColor = [UIColor blackColor];
                lbl1.backgroundColor = [UIColor clearColor];
                lbl1.highlightedTextColor = [UIColor whiteColor];
                lbl1.opaque = NO;
                lbl1.adjustsFontSizeToFitWidth = TRUE;
                lbl1.numberOfLines = 0;
                lbl1.lineBreakMode = UILineBreakModeWordWrap;
                [cell.contentView addSubview:lbl1];
            } else {
                lbl1 = (UILabel *)[cell.contentView viewWithTag:k1];
            }
            cell.accessoryView.tag = indexPath.row;
            lbl1.text = [NSString stringWithFormat:@"%@", cellValue];
            return cell;
        }
    }
}