In my main view I have a header (label) and footer (button). In the middle there is a table. Table takes data from MutableArray so number of table items is different each time.
Before and behind a table I have some vertical spaces (set by constraints) because I want to have some space between header/footer and table. So now a table is spread over whole "middle" part. This is OK.
What I want achieve to is that I don´t want to spread it over whole middle part. I want table to resize according to its content. If a table has only one row, I want to show one row and none of empty rows. I tried this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int count = accController.connectedAccessories.count;
[tableView setContentSize:CGSizeMake(tableView.contentSize.width, tableView.rowHeight * count)];
return count;
}
But this doesn't work. If I add this line after setContentSize
:
tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.contentSize.height);
This works but If I have many of items, constraints are broken and table is over a footer. Any ideas how to do this? Thanks
EDIT: This header and footer aren´t part of the table. I just put label (I call it header) and button (footer) into main view. And between them I put a table. It looks better for my purpose. I call it header and footer but they are header/footer of the main view, not a table...