我創建了一個UISplitViewApplication作爲我的新項目。在potrait模式下,我有一個按鈕,點擊後會下拉UITableView。它看起來如下所示:UITableView佈局不刷新,直到滾動
當我點擊了行之一,這是的UITableView駁回。後來,當我再次點擊組按鈕,呈現的UITableView的佈局,現在所有的凌亂:
然而,當我滾動的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;
}
是你的'UITableViewCells'有動態高度嗎? – 2011-05-10 13:52:22
是的,它有動態的高度..我剛剛上傳了這個代碼 – aherlambang 2011-05-10 13:55:10
,並且還嘗試使'CellIdentifier'成爲我的(動態)。 – 2011-05-10 13:57:30