gpt4 book ai didi

iphone - iOS-如何计算UITableViewCell的默认textLabel的宽度?

转载 作者:行者123 更新时间:2023-12-01 16:55:35 24 4
gpt4 key购买 nike

我尝试了下面的代码,但输出始终为0.000000:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellNotification";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.text = @"Test Test Test. I am a cell.";

NSLog(@"%f", cell.textLabel.frame.size.width);

return cell;
}

我怎么知道默认的UITableViewCell的宽度是多少?我需要此信息,因为我必须在以下位置设置UITableViewCell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

最佳答案

单元格的宽度将是表格的宽度,除非将表格分组,在这种情况下,表格会稍小一些。

但是,您可能想要用于显示文本的标签的宽度,而不是单元格本身的宽度。

进一步的警告是,在创建任何单元之前,表中的每一行都会调用heightForRow...方法,因此您可能不得不使用一个已知值。

关于iphone - iOS-如何计算UITableViewCell的默认textLabel的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12123658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com