代码之家  ›  专栏  ›  技术社区  ›  Trygve

nstableview binding+delegate导致数组索引错误

  •  0
  • Trygve  · 技术社区  · 7 年前

    我有一个基于视图的nstableview,它使用到nsarraycontroller的绑定。

    一旦我将一个委托添加到表视图中,我就开始得到:

    Ignoring exception raised in void run_cocoa_block(void *): *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
    

    MyApp[59144:25384659] *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
    MyApp[59144:25384659] (
        0   CoreFoundation    0x00007fff93410452 __exceptionPreprocess + 178
        1   libobjc.A.dylib   0x00007fff9601af7e objc_exception_throw + 48
        2   CoreFoundation    0x00007fff93327775 -[__NSArrayM objectAtIndex:] + 245
        3   AppKit            0x00007fff9bd7ad31 -[NSTableRowData _addViewToRowView:atColumn:row:] + 535
        4   AppKit            0x00007fff9bd7a98e -[NSTableRowData _addViewsToRowView:atRow:] + 184
        5   AppKit            0x00007fff9bd791a7 -[NSTableRowData _initializeRowView:atRow:] + 390
        6   AppKit            0x00007fff9bd77907 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 416
    

    如果我删除代理连接,一切正常…表从它绑定到的nsarraycontroller正确填充,单元格/列也得到正确的数据。

    我需要代表使用

    -(BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
    

    这可能是什么原因?

    在应用程序的其他地方,我有一个工作表,它还使用了一个基于视图的带绑定的nstableview,并且可以很好地处理委托。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Trygve    7 年前

    在awakefromnib:,我打电话给:

    [[self itemsController] setContent:[[[NSMutableArray alloc] init] autorelease]];
    

    这在基于单元格的nstableview中有效,但在基于视图的nstableview中无效。我不知道为什么,但是给它这个空数组可能是在绑定发生之后,但是在操作系统对它做了其他事情之前,空数组把它弄糊涂了。