gpt4 book ai didi

iphone - 动态UITableViewCell高度

转载 作者:行者123 更新时间:2023-12-01 19:23:53 25 4
gpt4 key购买 nike

我试图让我的单元格根据单元格中的文本数量动态地改变高度。.目前,我有自动换行..但只要该单元格有很多内容(如果它转到第三行) ),您看不到第二行之后的任何内容。

到目前为止,这就是我所拥有的..希望有人可以看到我是否缺少某些东西或做错了什么...任何帮助将不胜感激。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UILabel *label = nil;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setLineBreakMode:UILineBreakModeWordWrap];
[label setMinimumFontSize:FONT_SIZE];
[label setNumberOfLines:0];
[label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[label setTag:1];

[[cell contentView] addSubview:label];
}

// //Display cells with data that has been sorted from startSortingTheArray
NSArray *keys = [self.letterDictionary objectForKey:[self.sectionLetterArray objectAtIndex:indexPath.section]];
NSString *key = [keys objectAtIndex:indexPath.row];

CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

CGSize size = [key sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

if (!label)
label = (UILabel*)[cell viewWithTag:1];

[label setText:key];
[label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];






//Applise current key value to cell text label
//cell.textLabel.text = key;
return cell;
}

//Cell size for word wrapping.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{

//Display cells with data that has been sorted from startSortingTheArray
NSArray *keys = [self.letterDictionary objectForKey:[self.sectionLetterArray objectAtIndex:indexPath.section]];
NSString *key = [keys objectAtIndex:indexPath.row];

NSLog(@"%@", key);

CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

CGSize size = [key sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

CGFloat height = MAX(size.height, 44.0f);

return height + (CELL_CONTENT_MARGIN * 2);
}

更新上面的代码现在是一个工作版本..反正对我来说:)

最佳答案

重新开始并按照本教程中的单词学习,您会很好的:
Cocoa is My Girlfriend

实际上,您看起来像是在看本教程,只是跟随了一部分。我仍然看不到您设置标签的框架。

关于iphone - 动态UITableViewCell高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8903369/

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