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
I understand what you're trying to do. Here is what you should do:
- (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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With