title: How to set height of UITableView to solve scrolling issue?
body: <p><strong>Background</strong>: I'm working on my first iOS app that uses a UITableView for data being loaded dynamically from a web source.  No, this is not homework.</p>
  
  <p><strong>Problem</strong>: When I scroll down the list bounces back to the top.  </p>
  
  <p><strong>Things I've Tried</strong>: </p>
  
  <ol>
  <li>This <a href="https://stackoverflow.com/a/1507986/2521004">suggestion</a> (reducing the size of the table view) works but now I have large space at the bottom of the screen.</li>
  <li>I've tried using <code>[tableView reloadData]</code> but this doesn't changing the behavior.  I even hooked this up to a button to make sure it was firing after the view was populated.</li>
  <li>I also read a few post about <code>contentSize</code> and how to calculate based on the amount of data loaded in the table.  This looks like the solution I need but am having trouble getting a clear explanation of how to implement it for my setup.</li>
  </ol>
  
  <p><strong>Code</strong>:</p>
  
  <p>I started a new project with single view application template and added a <code>UITableView</code> to the default view in the main storyboard.  </p>
  
  <p>In view controller I have the following (relevant) code:</p>
  
  <pre><code>@interface ERViewController ()
  @property (nonatomic, strong) NSMutableArray *myArray;
  @property (nonatomic,retain) UITableView *tableView;
  @end
  
  @implementation ERViewController
  {
      NSMutableArray *tableData;
  }
  </code></pre>
  
  <hr>
  
  <p>Here I am loading the data from Parse.com into my table and then calling <code>[self loadView]</code> to get the view to update after the query finishes.</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      NSMutableArray *returnedData = [[NSMutableArray alloc] init];
  
      PFQuery *query = [PFQuery queryWithClassName:@"Persons"];
      [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
          if (!error) {
              for (PFObject *object in objects) {
                  //NSLog(@"display name: %@",object[@"firstName"]);
                  [returnedData addObject:[NSString stringWithFormat:@"%@, %@", object[@"lastName"],object[@"firstName"]]];
              }
  
              tableData = returnedData;
  
              // Reload view to display data
              [self loadView];
          } else {
              NSLog(@"Error: %@ %@", error, [error userInfo]);
          }
      }];
  }
  </code></pre>
  
  <hr>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *simpleTableIdentifier = @"SimpleTableItem";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
  
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
      }
  
      // Configure the cell
      cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
  
      NSArray *itemArray = [NSArray arrayWithObjects: @"✔︎", @"?", @"X", nil];
  
      UISegmentedControl *mainSegment = [[UISegmentedControl alloc] initWithItems:itemArray];
  
      mainSegment.frame = CGRectMake(200,0, 100, 43);
      self.navigationItem.titleView = mainSegment;
      mainSegment.selectedSegmentIndex = [itemArray count];
  
      [mainSegment addTarget:self
                      action:@selector(mainSegmentControl:)
            forControlEvents: UIControlEventValueChanged];
      mainSegment.tag = indexPath.row;
  
      [cell.contentView addSubview:mainSegment];
  
      return cell;
  }
  </code></pre>
  
  <hr>
  
  <p>Sample screen shot:</p>
  
  <p><img src="https://i.stack.imgur.com/RjAig.png" alt="enter image description here"></p>
  
  <hr>
  
  <p>Since I'm waiting for the data to load I'm not sure where to resize the view and how exactly I need to resize the view.</p>