Change UITableView height dynamically iOS7

ios, objective-c, uitableview

Solution

I understand what you're trying to do. Here is what you should do:

- Add height constraint to your UITableView

- Wrap it in custom UIView

- Make a custom class MyCustomView:UIView

- Set class in IB for your wraper UIView to your class from step 3.

- Make connection from constraint in IB to your class

- Make a connection between table view and your class

- Put code into your new class:

- (void) layoutSubviews {
  // set height 0, will calculate it later
  self.constraint.constant = 0;

  // force a table to redraw
  [self.tableView setNeedsLayout];
  [self.tableView layoutIfNeeded];

  // now table has real height
  self.constraint.constant = self.tableView.contentSize.height;
}

Problem

Please help me to ask this question. I tried all the choices that I could find here. The sample of my code is attached (I know, it's pretty bad). How can I change `UITableView` height dynamically? ``` - (void)viewDidLoad { [super viewDidLoad]; [self vozvratmassiva]; } - (NSMutableArray *) vozvratmassiva { ... return array; } -(NSInteger)numberOfSectionInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *a = [self vozvratmassiva]; return a.count; } -(UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { .... return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { .... return commonsize; } @end ```

Original source

Related problems