I have three UITableViews that should look identical. Each is placed inside a different subview of a UIScrollView. As I scroll, I can see each table. The first table appears perfectly. However, only the background color shows for the second and third tables.
tableView:cellForRowAtIndexPath: is being called for every row for each table, where I insert a subview into the cell’s contentView. The subview has already been created before this method is called and is reused across the three tables for a given row (in an attempt to make tables look identical).
I made two interesting discoveries:
- Although the cell doesn’t show initially, it will appear after scrolling to hide the row and then show it again.
- When the cell appears after scrolling, it has been moved from another table. It no longer appears in the table where it had been showing.
Here’s my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"PlotCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PlotCell" owner:self options:nil];
if ([nib count] > 0)
cell = self.plotCell;
else
NSLog(@"Failed to load AlertCell nib!");
}
// Set up the cell...
NSUInteger row = [indexPath row];
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
ResultSet *rs = del.resultPlots;
CPTGraphHostingView *cellPlotView = [rs.hostingViews objectAtIndex:row];
cellPlotView.frame = cell.contentView.bounds;
cellPlotView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell.contentView insertSubview:cellPlotView atIndex:0];
return cell;
}
cellPlotView refers to the subview already created.
Any idea how to fix this so I can see all my tables correctly showing as I scroll? It’s as if the cells can’t reuse content. Thanks.
View can have only one superview. So create 3 identical CPTGraphHostingView views.