1
votes

I have created a view based NSTableView with custom cells. Each cell has an image(from net) in it. On selecting am showing a custom selection indicator(something like a check mark).

When any cell gets clicked it will modify that cell's property called isClicked to YES in tableViewSelectionDidChange delegate. Once done I will make a call to reload table data. While reloading a check is made to see if that cell was selected and if selected the selection indicator image will be displayed.

Until now cell image were from local, but now am using cell image from net. And this is loaded using dispatch async queue Since table gets reloaded all of these images gets downloaded again, and it sort of flickers on the screen. How can this be avoided ?

1

1 Answers

0
votes

My solution with ugly code, but worked:

- (void)tableViewSelectionDidChange:(NSNotification *)notification{    

    NSTableView *tableView = [notification object];

    NSInteger row = [tableView selectedRow];

    [self markSelectedCellForTable:tableView withRow:row];

    if ([_foldersList count]) {
        _currentFolder = [_foldersList objectAtIndex:row];

        [tableView scrollRowToVisible:row];
    }else{
        _currentFolder = nil;
    }

    NSLog(@"Folder %@",(_currentFolder)?[_currentFolder title]:@" not selected");
}

- (void)markSelectedCellForTable:(NSTableView *)tableView withRow:(NSInteger)row{

//ui
@try {
        NSTableRowView *rowView;
        NSTableCellView *cellView;
        for (int i=0; i<=[_foldersList count]; i++){

            rowView = [tableView rowViewAtRow:i
                              makeIfNecessary:NO];

            cellView = [[rowView subviews] objectAtIndex:0];

            [[cellView imageView] setHidden:(i!=row)];
        }

    }
    @catch (NSException *exception) {}
}