Tableview显示错误的单元格大小

在表中我设置单元格的高度使用(heightForRowAtIndexPath)委托的表视图的代码是:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } 

但我在委托方法(cellForRowAtIndexPath)检查单元格的大小和代码是:

  - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Dequeue or create a cell UITableViewCellStyle style = UITableViewCellStyleDefault; UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:@"BaseCell"]; if (!cell) cell = [[UITableViewCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell"] ; cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", numberOfItems - indexPath.row]; NSLog(@"%f",cell.frame.size.height); return cell; } 

当我打印的价值(细胞的框架)单元格在控制台上给我44.00.Why这是发生,即使我正在设置单元格的高度..请解释我和做什么来获得单元格高度100 ..感谢提前

其实我想制作自定义types的表视图,支持不同的视图方向,它是通用的应用程序,所以它将更好地调用单元格的大小代表每次检查(iphone / ipad,diff或inintation)…. plz帮助我完成要求

如果单元格正确显示,正确的意思是你的tableView:heightForRowAtIndexPath:有100个像素的高度,我敢肯定这是因为你要求单元格的高度在错误的地方:该单元刚刚被默认的初始化方法初始化,所以返回的高度是默认的,在你的控制台中nslog提示44像素,在渲染委托设置从你的方法返回正确的高度,一切都设置正确。

我有几个月前的这个问题,由于某些原因,我需要知道单元格的高度在tableView:cellForRowAtIndexPath:方法,我出来了一个解决方法:我已经存储所有rowHeights值在一个NSArray ,因为他们是dynamic和不同的按其内容逐行排列。

我出来了类似的东西

CGFloat height = [[heightsData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

你有设置你的代表UITableViewDelegate?

尝试把任何日志在你的tableView:heightForRowAtIndexPath:方法,首先看看你的代表是否设置。

您好朋友dev已经给出了解释

  NSLog(@"%f",[self tableView:tableView heightForRowAtIndexPath:indexPath]);