gpt4 book ai didi

iphone - UITableView 布局在滚动之前不会刷新

转载 作者:行者123 更新时间:2023-12-03 20:46:23 26 4
gpt4 key购买 nike

我创建了一个 UISplitViewApplication 作为我的新项目。在肖像模式下,我有一个按钮,单击该按钮将下拉 UITableView。它看起来如下所示:

enter image description here

当我单击其中一行时,此 UITableView 将被关闭。然后,当我再次单击“组”按钮时,呈现的 UITableView 的布局现在变得一团糟:

enter image description here

但是,当我滚动 TableView 以便再次重新加载某些行时,重新加载的行将被格式化。这是为什么?我该如何解决这个问题?

这是我的索引路径行的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MyCell";

MyCell *cell = (ConvoreCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:nil options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (MyCell *) currentObject;
break;
}
}
cell.delegate = self;
// }


if ([posts count] > 0){
cell.star.hidden = YES;

[lazyImages addLazyImageForCell:cell withIndexPath:indexPath];
cell.title.text = [[posts objectAtIndex:indexPath.row] message];

cell.detailed.autoresizesSubviews = YES;
cell.detailed.text = [NSString stringWithFormat:@"%@", [[[posts objectAtIndex:indexPath.row] creator] username]];


if ([[[posts objectAtIndex:indexPath.row] embeds] count] != 0){
NSString * URL = [[[[posts objectAtIndex:indexPath.row] embeds] objectAtIndex:0] url];
float height = [[(Embed * )[[[posts objectAtIndex:indexPath.row] embeds] objectAtIndex:0] height] floatValue];
float width = [[(Embed * )[[[posts objectAtIndex:indexPath.row] embeds] objectAtIndex:0] width] floatValue];
[cell.embed setFrame:CGRectMake(cell.detailed.frame.origin.x, cell.detailed.frame.origin.y + 15, width, height)];
cell.embed.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:URL]]];
}

if ([[[posts objectAtIndex:indexPath.row] stars] count] != 0){
cell.star.hidden = NO;
cell.star_creator.text = [(Login *)[[[[posts objectAtIndex:indexPath.row] stars] objectAtIndex:0] user] username];
}

}
return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText =[[posts objectAtIndex:indexPath.row] message];
UIFont *cellFont = [UIFont fontWithName:@"Arial" size:14.0];
CGSize constraintSize = CGSizeMake(600.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
float height = 0.0;

if ([[[posts objectAtIndex:indexPath.row] embeds] count] != 0)
height = [[[[[posts objectAtIndex:indexPath.row] embeds] objectAtIndex:0] height] floatValue];

if (labelSize.height + 20 + height < 48)
return 55;
else
return labelSize.height + height + 48;

}

最佳答案

转发自之前的评论:重新加载 viewWillAppear 中的可见单元格。

关于iphone - UITableView 布局在滚动之前不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5945325/

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