I need to create a custom tableViewHeader in which at least two shortcuts should be displayed, namely: project_name and project description. The contents of these two labels change (i.e. in terms of line length).
I managed to get a working version for the deviceβs default orientation (portrait), but if the user rotates the device to the landscape, the width of my user header does not change and the user sees unused empty space on the right.
The following code snippet is used:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 50.0f; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { CGFloat wd = tableView.bounds.size.width; CGFloat ht = tableView.bounds.size.height; UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0., 0., wd, ht)]; headerView.contentMode = UIViewContentModeScaleToFill;
I noticed that tableView:viewForHeaderInSection: will only be called once after viewDidLoad , but not after changing the orientation of the device.
Should I implement the willRotateToInterfaceOrientation: method with something like:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self.tableView reloadSections:nil withRowAnimation:UITableViewRowAnimationNone]; }
I can't figure out how to make reloadSections: work by forcing recalculating my customView.
source share