I have a popover screen, with inside it :
- a label, that may or may not appear (title)
- a search bar, that may or may not appear
- a label, that may or may not appear, and has a variable height (help label)
- a scrollview, that may or may not appear, and has a variable height (some infos about the following table)
- a table view
In order to present something nice, in viewDidLoad
, I move the various frames to place the objects correctly and not have unused spaces cluttering my popover. Besides, I then resize the table (to take the most place needed), and the popover via contentSizeInPopover
(to avoid having a near-empty huge popover). All that resizing seems to work nicely, but I have one big problem : with all that resizing done, some cells of my UITableView become unresponsive. One or two cells, usually the second one, only respond if i tap in their outer corners, but the rest of the cell completely ignore any touches.
I've tried everything : moving all to viewWillAppear
, letting the autoresize do its job (doesn't seem to work either), but I still have this problem every time. I've found that if I comment the lines involved with changing the frame
of the table, or the ones in contentSizeInPopover
, the problem stops, but then my view is messed up, so this ins't a fix.
If anyone could give me something to get out of this mess, that would be awesome.
- (CGFloat)getHeightWithoutTable { return LIST_TITLE_HEIGHT + (self.searchBar.hidden ? 0 : LIST_SEARCH_BAR_HEIGHT) + (self.helpLabel.hidden ? 0 : self.helpLabel.frame.size.height + LIST_STD_SPACE) + (self.errorScrollView.hidden ? 0 : self.errorScrollView.frame.size.height + LIST_STD_SPACE); } -(void)viewDidLoad { [super viewDidLoad]; self.tableViewOutlet.backgroundView = nil; self.originData = [NSMutableArray array]; self.searchedData = [NSMutableArray array]; if (self.helper != nil) { CGFloat heightOffset = 0; // Content self.originData = [self.helper getData]; self.tableData = [NSMutableArray arrayWithArray:self.originData]; // Title NSString *title = [self.helper getPopoverTitle]; if (title == nil) { self.popoverTitle.hidden = YES; heightOffset -= LIST_TITLE_HEIGHT; } else { self.popoverTitle.text = [self.helper getPopoverTitle]; } // Search if ([self.originData count] [self getStdHeight] / 3){ self.helpLabel.lineBreakMode = UILineBreakModeTailTruncation; [self.helpLabel sizeThatFits:CGSizeMake(self.helpLabel.frame.size.width, [self getStdHeight] / 3)]; } heightOffset += (self.helpLabel.frame.size.height - LIST_HELP_STD_HEIGHT); } // Errors if ([self.helper respondsToSelector:@selector(getErrors)]) { self.errors = [self.helper getErrors]; } if (self.errors == nil || [self.errors count] == 0) { self.errorScrollView.hidden = YES; self.errorBg.hidden = YES; heightOffset -= LIST_ERROR_STD_HEIGHT + LIST_STD_SPACE; } else { [self createErrorView]; heightOffset += (self.errorScrollView.frame.size.height - LIST_ERROR_STD_HEIGHT); } // Table CGFloat previewHeight = LIST_CELL_HEIGHT * [self.tableData count] + LIST_STD_SPACE; CGFloat remainingHeight = LIST_MAX_HEIGHT - [self getHeightWithoutTable] - LIST_STD_SPACE; CGFloat tableHeight = MIN(previewHeight, remainingHeight); CGRect tableFrame = self.tableViewOutlet.frame; self.tableViewOutlet.frame = CGRectMake(tableFrame.origin.x, tableFrame.origin.y + heightOffset, LIST_WIDTH, tableHeight); // Selected items if ([helper getSelectedObject] != nil){ int index = [self.tableData indexOfObject:[helper getSelectedObject]]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0]; [self.tableViewOutlet scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; } } } - (CGSize)contentSizeForViewInPopover { if (self.navigationController) { return CGSizeMake(LIST_WIDTH, LIST_MAX_HEIGHT); } else { CGFloat totalHeight = [self getHeightWithoutTable] + self.tableViewOutlet.frame.size.height + LIST_STD_SPACE; return CGSizeMake(LIST_WIDTH, totalHeight); } }
(gist if you need some coloring to help you)
An image of the nib :