如何编辑自定义UITableViewCell框架大小?

时间:2011-07-02 08:47:35

标签: iphone

我使用自定义UITableViewCell类来制作表格视图单元格。我正在动态更改行高:

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

它完美地适用于行高。

但这只会改变行高,而不是Cell的Frame高度。单元格框架高度仍为44(默认值)。那么如何才能使它对行高和单元格框架都有效呢?

提前致谢..

2 个答案:

答案 0 :(得分:0)

在cellforrow中创建单元格时

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
 {

  UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];

 if (cell == nil) 
 {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,90,90) reuseIdentifier:@"MyIdentifier"] autorelease];
 }
return cell;

}

请注意这一行

     cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,90,90) reuseIdentifier:@"MyIdentifier"] autorelease];

CGRectMake(0,0,90,90)根据需要更改此内容

答案 1 :(得分:0)

只需在cellForRowIndexAtPath:数据源方法中写一行。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
   cell.frame = CGRectMake(0,0,320,60);

}
相关问题