0

I want to refresh and resize my Table view according to the size of no of items in the array to populate in table view when a subview is removed from a super view. I am doing it by creating a frame which increases height by 50 for each increasing item. Here is my code

- (IBAction) doneAddingUsers:(id)sender {

    [self.crewTable setHidden:NO];
    [self.crewTable reloadData];
    self.crewTable.frame = CGRectMake(self.crewTable.frame.origin.x, self.crewTable.frame.origin.y, self.crewTable.frame.size.width, [crewArray count]*50);

    NSLog(@"height: %f", crewTable.frame.size.height);
    [self.view bringSubviewToFront:self.crewMembersView];
    [self.crewMembersView removeFromSuperview];
}

In log it is showing the right height but in UI its not seems that height of table view is changed. I have disabled scrolling too

Thanks in advance

BergQuester
  • 6,167
  • 27
  • 39
Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57
  • I have not tested this, but I would imagine that you should set the frame *and then* call reloadData. Not the other way around as you have it. – lnafziger Jul 27 '13 at 02:17

1 Answers1

2

Instead of setting up the frame in doneAddingUsers:, you can do this:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int count = [crewArray count];

    //Set the height of the tableview
    CGRect frame = self.tabPackageList.frame;

    frame.size.height = (count * 50);

    [self.tabPackageList setFrame:frame];

    // Return the number of rows in the section.
    return count;
}
ZeMoon
  • 20,054
  • 5
  • 57
  • 98