获取在大小选择器中设置的UITableView高度

获取在大小选择器中设置的UITableView高度,uitableview,ios7,Uitableview,Ios7,我有一个占据大部分视图的UITableView。 我想根据从数据库收集的行数动态设置行高。 当选择UITableView时,大小选择器表示高度为504 如何在代码中获得该值?在填充行之前需要该值。为UITableView创建一个属性,例如: // IBOutlet optional; you could be making the UITableView in code @property (strong, nonatomic) IBOutlet UITableView *tableView;

我有一个占据大部分视图的UITableView。 我想根据从数据库收集的行数动态设置行高。 当选择UITableView时,大小选择器表示高度为504


如何在代码中获得该值?在填充行之前需要该值。

UITableView
创建一个属性,例如:

// IBOutlet optional; you could be making the UITableView in code
@property (strong, nonatomic) IBOutlet UITableView *tableView; 
然后,得到如下高度:

CGFloat height = self.tableView.frame.size.height;
- (CGFloat)       tableView:(UITableView *)tableView 
    heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    int numberOfRows = // some way to figure this out 
                       // (or maybe it's already determined)

    CGFloat height = self.tableView.frame.size.height;

    return height / numberOfRows; // or whatever your desired equation is

}

UITableView
数据源协议实现中,执行以下操作:

CGFloat height = self.tableView.frame.size.height;
- (CGFloat)       tableView:(UITableView *)tableView 
    heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    int numberOfRows = // some way to figure this out 
                       // (or maybe it's already determined)

    CGFloat height = self.tableView.frame.size.height;

    return height / numberOfRows; // or whatever your desired equation is

}

任何时候您的数据更新,只要调用
[self.tableView reloadData]
就会强制刷新。

谢谢!如果你选择了我的答案,请你也投票吧?