I have a NSTableView
with 10 cells. They are all the same cells and I want to reuse them, however I can't seem to get the table view to do so.
Currently, each time a new cell is needed, the delegate cannot seem to find the previous cell with the same identifier and has to recreate it.
Below is my code, any suggestions on what I might be doing wrong?
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return 10;
}
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
static NSString *cellIdentifier = @"Name";
NSTableCellView *cellView = [tableView makeViewWithIdentifier:cellIdentifier owner:self];
if (cellView == nil)
{
NSLog(@"A cell");
NSRect cellFrame = [_scrollView.contentView bounds];
cellFrame.size.height = 65;
cellView = [[NSTableCellView alloc] initWithFrame:cellFrame];
[cellView setIdentifier:cellIdentifier];
}
return cellView;
}
I did some testing and noticed that the table will continually create new cells until the table cannot display all cells at the same time.
At this point, the table will reuse the cells that are not visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With