Get UITableView Height set in Size Selector

I have a UITableView that takes up most of a View. I want to dynamically set the row height based on the number of rows gathered from my database. When the UITableView is selected, Size Selector say the height is 504.

How do I get that value in code? In need that value before I populate the rows.


Make a property for the UITableView, such as:

// IBOutlet optional; you could be making the UITableView in code
@property (strong, nonatomic) IBOutlet UITableView *tableView; 

Then, get the height like this:

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

In your UITableView Data Source Protocol implementation, do something like this:

- (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


Anytime your data updates, a call to [self.tableView reloadData] will force a refresh.

Need Your Help

main thread not waiting for async to compelte

ios multithreading asynchronous unirest

10I've followed a few posts on SOF regarding async calls using GCD and this works fine IF the remote server response is quick enough ,like when working and testing against a local test server.

Android: Translate Animation and Relative Layout

android android-layout android-animation

I want to reveal a View by moving everything below where it is going to apear, and then make it visible (giving the effect that the items below it just slid to made room for it). I am currently usi...