调整UITableView的大小

问题描述:

我正在处理该项目。目前我正面临一个问题,我在一个ViewController中有3个UITableView。它看起来是这样的:

enter image description here调整UITableView的大小

现在,第一个TableView中(上一个),只有一个排,具有大小55个像素,它不;吨必须改变大小。接下来,第二个是TableView,也是一行,但这行必须调整大小取决于它的内容。眼下这个TableView中显示此行:

enter image description here

这行必须调整大小取决于它的文本多久。我所做的计算大小是:

if(tableView == self.usersPostOnTheWallTableView) { 
    NSDictionary *propertyItems = [self.repliesItems objectAtIndex:indexPath.row]; 

    NSString *text = [self.postItems objectForKey:@"text"]; 

    NSLog(@"%@", text); 

    CGSize constraintSize = CGSizeMake(280, MAXFLOAT); 

    CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; 

    self.height = MAX(sizeText.height, 44.0f); 

    self.photosArray = [propertyItems objectForKey:@"attach_photos"]; 
    self.videosArray = [propertyItems objectForKey:@"attach_videos"]; 

    if((self.photosArray.count == 0) && (self.videosArray.count == 0)) { 

     height += (CELL_CONTENT_MARGIN * 2); 

    } else if ((self.videosArray.count > 0) && (self.photosArray.count == 0)) { 

     height += 90 + (CELL_CONTENT_MARGIN * 2); 

    } else if((self.photosArray.count > 0) && (self.videosArray.count == 0)) { 

     height += 85 + (CELL_CONTENT_MARGIN * 2); 
    } 

} 

现在,如果文本很小,它适合行很好,行是调整大小。像这样的:

enter image description here

但是,短信来了更大的后,这是什么发生的事情:

enter image description here

enter image description here

很显然,我不需要在那里的滚动和我会禁用它。但是这里的事情是它需要文本的大小,并且它调整了标签的大小,你可以看到从标签的顶部和底部有多少空间。但它并没有把实际的文字放在那里。另一件事是,它没有调整自己的TableView的大小,当我试图调整它的大小时,我得到了中间表的底部表的重叠。

任何人都可以推荐任何解决方案,或者可能是另一种实现方式吗?

在此先感谢!

+0

为什么你在第一个和第二个视图中使用UITableView?第一个只是一个按钮,看起来像一个表格行,第二个只是一个文本视图,那么为什么你的生活复杂化? :-) – lawicko 2012-07-26 09:08:21

+0

第二个我需要显示一行,因为还会有图像和视频。 – 2012-07-26 09:09:17

+0

视频和图片仍然没有成为一张桌子。对于脱离主题感到抱歉,但当设计看起来如此之差时,我无法专注于技术细节。 – lawicko 2012-07-26 09:11:37

U可以做到这一点是使用tableviewDelegate方法根据您的文字是这样,例如设置单元格高度:

这个方法将被调用每一个细胞,以决定应该有多少细胞具有高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *strDetails = [yourTextArray objectAtIndex:indexPath.row]; 
    //if(indexPath.row == 1) 
    //{ 
    CGSize stringSize = [strDetails sizeWithFont:[UIFont fontWithName:@"Marker Felt" size:13] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:UILineBreakModeWordWrap]; // Provide text as well as font name in which your text will be displayed and constrainedToSize which defines width and height it should be maximum 
    return stringSize.height+65; //Here 65 can be any value depending on Calculation ImageView height + uppermost space + bottom space added 
    //} 
    //else 
    //{ 
    // return 80 // anything u wishes 
    //} 
}