Note that there are some explanatory texts on larger screens.

plurals
  1. PONSOutlineView rowForItem: always returns 0
    primarykey
    data
    text
    <p>I have an app which needs to update cells in certain columns asynchronously. I have a GCD queue which blocks are added to which later gets the cell for the row and column given using <code>-rowForItem:</code> but the result of <code>-rowForItem:</code> is consistently 0, and <code>NSAssert([self.outlineView itemAtRow:row] == item, @"rowForItem: and itemForRow: not reversible! (Item %@, row %ld)", item, (long)row);</code> throws every time. I don't see what I'm doing wrong here. The index is not -1, which means that the item wasn't found, but the item is said to be at the incorrect index. (The first item is always a JODirectoryInfo, and I only run the block on JOFileInfo, so it can't be the wrong item.)</p> <pre><code>- (NSTableCellView *)_cellForRow:(NSInteger)row columnIdentifier:(NSString *)column { if (row &lt; 0) return nil; NSInteger colIdx = [self.outlineView columnWithIdentifier:column]; if (colIdx == -1) return nil; if (colIdx + 1 &gt; 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"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload