2011-07-02 105 views
0

我正在使用自定义的UITableViewCell类来制作表格视图单元格。我正在动态改变行高:如何编辑自定义UITableViewCell的帧大小?

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

它的行高度完美。

但是,这只改变了行高,而不是Cell的Frame高度。单元框架高度仍然是44(默认)。那么我怎样才能使它对行高和细胞框架都有效?

在此先感谢..

+0

Patidar:你怎么知道**细胞框架高度是44而不是60 **? – Jhaliya

+0

我正在使用断点调试应用程序。在tableViewCell类中,我使用self.frame.size.height来获取单元格高度。 –

回答

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 )根据你的需要改变它

+0

大家好,感谢您的回复。但这对我的情况还不够。这些似乎是在init方法中传递静态单元框架。我想要一个动态单元格高度,它应该与行高相同。注意:在我的情况下,行高不会是静态的。例如,我只用了60。 –

0

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

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

} 
相关问题