2013-06-28 112 views
0

我有一個應用程序需要在某些列中異步更新單元格。我有一個GCD隊列,其中添加了塊,稍後獲取使用-rowForItem:給出的行和列的單元格,但-rowForItem:的結果始終爲0,並且每次都拋出NSAssert([self.outlineView itemAtRow:row] == item, @"rowForItem: and itemForRow: not reversible! (Item %@, row %ld)", item, (long)row);。我沒有看到我在這裏做錯了什麼。該索引不是-1,這意味着該項目未找到,但該項目被認爲位於不正確的索引處。 (第一項總是JODirectoryInfo,我只上JOFileInfo運行塊,所以它不可能是錯誤的項目。)NSOutlineView rowForItem:總是返回0

- (NSTableCellView *)_cellForRow:(NSInteger)row columnIdentifier:(NSString *)column { 
    if (row < 0) return nil; 
    NSInteger colIdx = [self.outlineView columnWithIdentifier:column]; 
    if (colIdx == -1) return nil; 
    if (colIdx + 1 > self.outlineView.tableColumns.count) return nil; 
    return [self.outlineView viewAtColumn:colIdx row:row makeIfNecessary:NO]; 
} 
- (NSTableCellView *)_cellForItem:(id)item columnIdentifier:(NSString *)column { 
    NSInteger row = [self.outlineView rowForItem:item]; 
    NSAssert([self.outlineView itemAtRow:row] == item, @"rowForItem: and itemForRow: not reversible! (Item %@, row %ld)", item, (long)row); 
    DDLogVerbose(@"Getting cell for item %@ (row %ld) in column %@", item, (long)row, column); 
    return [self _cellForRow:row columnIdentifier:column]; 
} 

- (dispatch_block_t)_loadingBlockForItem:(JOFileInfo *)item block:(JOFileInfoBlock)block column:(NSString *)columnIdentifier { 
    return ^{ 
     NSTableCellView *cellView = [self _cellForItem:item columnIdentifier:columnIdentifier]; 
     if (!cellView) return; 
     cellView.objectValue = block(item); 
    }; 
} 
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item { 
    DDLogVerbose(@"Requested value of column %@ for item %@", tableColumn.identifier, item); 
    if ([tableColumn.identifier isEqualToString:@"Size"]) { 
     if ([item isKindOfClass:[JOFileInfo class]]) { 
      dispatch_async(self.queue, [self _loadingBlockForItem:item block:^(JOFileInfo *item) { 
       unsigned long long size = item.size; 
       if (size != ULONG_LONG_MAX) return [self.byteCountFormatter stringFromByteCount:size]; 
       else return @"--"; 
      } column:tableColumn.identifier]); 
      return @"--"; 
     } else { 
      return @"--"; 
     } 
    } else { 
     return @"text"; 
    } 
} 

回答

0

它返回零,因爲大綱視圖爲零。