Uitableview 在ios 5中更改tableview行高

Uitableview 在ios 5中更改tableview行高,uitableview,ios5,Uitableview,Ios5,在ios 5之前,我会在tableview中设置行高,如下所示: self.tableView.rowHeight=71; ... @interface TableDelegate : UIViewController <UITableViewDelegate> ... or @interface TableDelegate : UIViewController <some_other_protocol, UITableViewDelegate> 但是,它在i

在ios 5之前,我会在tableview中设置行高,如下所示:

self.tableView.rowHeight=71;
...    
@interface TableDelegate : UIViewController <UITableViewDelegate>
...
or
@interface TableDelegate : UIViewController <some_other_protocol, UITableViewDelegate>
但是,它在iOS5上不起作用

有人有主意吗


谢谢

您是否尝试过
UITableViewDelegate
中的
tableView:heightForRowAtIndexPath:

您可以通过在
UITableView
代理(支持
UITableViewDelegate
协议的代理)中实现
tableView:heightforrowatinexpath:
将行高设置为71

首先,应该设置tableView的委托。委派应符合
UITableViewDelegate
协议。假设我们有一个
TableDelegate
类。要符合
UITableViewDelegate
协议,应将其置于声明的方括号中,如下所示:

self.tableView.rowHeight=71;
...    
@interface TableDelegate : UIViewController <UITableViewDelegate>
...
or
@interface TableDelegate : UIViewController <some_other_protocol, UITableViewDelegate>
最后,您应该在
TableDelegate
实现中实现
tableView:heightforrowatinexpath:
方法:

@implementation TableDelegate
...
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 71.0;
}
...
@end
行高
为了澄清这一点,正如Javier Soto在评论中指出的那样,使用
rowHeight
应该可以很好地工作,并且比从
-tableView:heightForRowAtIndexPath:
返回的常量性能更好。还要注意的是,如果UITableView在
-tableView:heightForRowAtIndexPath:
rowHeight
属性集中具有代理返回高度,则会使用先前的值。

对iOS 5进行Im编码,并且它实际上可以工作。您只需要实现您在中所说的内容:

 - (void)viewDidLoad
之后的方法:

[super viewDidLoad];
委员会:


如果TableView为空,则方法不起作用。但是,如果使用rowHeight属性,即使视图为空,它也会工作。

请尝试在
视图出现之前设置
rowHeight
,例如,在创建表视图之后

这让我在iOS 5上工作。在iOS 6上更容易:你可以在任何地方设置它


正如其他人所指出的,使用
rowHeight
的优点是可以避免
tableView:heightforrowIndexPath:

的性能影响。此方法是更改行的高度

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

检查Apple关于使用此实现而不是设置rowHeight的警告:使用tableView:heightForRowAtIndexPath:而不是rowHeight属性会影响性能。每次显示表视图时,它都会为其每一行在代理上调用tableView:heightForRowAtIndexPath:,这可能会导致具有大量行(大约1000行或更多行)的表视图出现严重的性能问题。
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return  51.0f
};