Skip to content

Instantly share code, notes, and snippets.

@talkol
Last active June 12, 2016 00:28
Show Gist options
  • Save talkol/c3d2a97a9edfd037ad1b520d0719649e to your computer and use it in GitHub Desktop.
Save talkol/c3d2a97a9edfd037ad1b520d0719649e to your computer and use it in GitHub Desktop.
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
// will not add them as subviews yet because we don't need to draw them
// [super insertSubview:subview atIndex:atIndex];
[_unusedCells addObject:subview];
}
- (UIView*) getUnusedCell {
UIView* res = [_unusedCells lastObject];
[_unusedCells removeLastObject];
if (res != nil) {
res.tag = [_unusedCells count];
}
return res;
}
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"CustomCell";
TableViewCell *cell = (TableViewCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.cellView = [self getUnusedCell];
NSLog(@"Allocated childIndex %d for row %d", (int)cell.cellView.tag, (int)indexPath.row);
} else {
NSLog(@"Recycled childIndex %d for row %d", (int)cell.cellView.tag, (int)indexPath.row);
}
// there's another interesting piece still missing here..
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment