Skip to content

Commit

Permalink
Load nib each time only for custom buttons
Browse files Browse the repository at this point in the history
This fixes a layout issue after sleep / resume.
  • Loading branch information
wutschel committed Jan 18, 2023
1 parent 7e02b92 commit 24955e5
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions XBMC Remote/RightMenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ - (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
/*
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rightMenuCellIdentifier"];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"rightCellView" owner:self options:nil];
Expand All @@ -91,17 +90,6 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
backView.backgroundColor = [Utilities getGrayColor:22 alpha:1];
cell.selectedBackgroundView = backView;
}
*/
// WORKAROUND BEGIN
// Load nib each time as otherwise the layout of the cells is not properly handled after sleep / resume.
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"rightCellView" owner:self options:nil];
UITableViewCell *cell = nib[0];

// Set background view
UIView *backView = [[UIView alloc] initWithFrame:cell.frame];
backView.backgroundColor = [Utilities getGrayColor:22 alpha:1];
cell.selectedBackgroundView = backView;
// WROKAROUND END

// Reset to default for each cell to allow dequeuing
UIImageView *icon = (UIImageView*)[cell viewWithTag:1];
Expand Down Expand Up @@ -175,6 +163,41 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
[cell.contentView addSubview:remoteControllerView.view];
}
else {
// WORKAROUND BEGIN
// Load nib each time as otherwise the layout of the cells is not properly handled after sleep / resume.
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"rightCellView" owner:self options:nil];
cell = nib[0];

// Reset to default for each cell to allow dequeuing
icon = (UIImageView*)[cell viewWithTag:1];
status = (UIImageView*)[cell viewWithTag:2];
title = (UILabel*)[cell viewWithTag:3];
line = (UIImageView*)[cell viewWithTag:4];
status.hidden = YES;
status.image = nil;
icon.hidden = NO;
icon.image = nil;
icon.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
icon.alpha = 0.6;
title.textAlignment = NSTextAlignmentRight;
title.numberOfLines = 2;
title.font = [UIFont fontWithName:@"Roboto-Regular" size:20];
title.autoresizingMask = UIViewAutoresizingFlexibleWidth;
title.frame = CGRectMake(RIGHT_MENU_TITLE_START,
0,
RIGHT_MENU_TITLE_WIDTH,
RIGHT_MENU_ITEM_HEIGHT);
title.text = @"";
cell.accessoryView = nil;
cell.editingAccessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (@available(iOS 13.0, *)) {
cell.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
}
cell.tintColor = UIColor.lightGrayColor;
NSString *iconName = @"blank";
// WORKAROUND END

cell.editingAccessoryType = UITableViewCellAccessoryDetailDisclosureButton;

CGRect frame = title.frame;
Expand Down

0 comments on commit 24955e5

Please sign in to comment.