【问题标题】:NSTableView binding + delegate causes array index errorNSTableView 绑定 + 委托导致数组索引错误
【发布时间】:2018-07-06 18:28:06
【问题描述】:

我有一个基于视图的 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 和绑定,它可以与委托正常工作。

【问题讨论】:

  • 如果不实现control:textShouldEndEditing:会怎样?
  • 同样的崩溃 - 它永远不会到达那个委托方法
  • 实现了哪些NSTableViewDelegate方法?
  • none - 文档说如果我使用绑定,我不需要提供 rowView 委托。这适用于其他地方没有委托方法。

标签: binding delegates nstableview


【解决方案1】:

在 awakeFromNib: 中,我正在调用:

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

这在基于单元格的 NSTableView 中有效,但在基于视图的 NSTableView 中无效。我不知道为什么,但是给它这个空数组可能是在绑定发生之后但在操作系统对其进行其他操作之前发生的,并且空数组会混淆它。

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    相关资源
    最近更新 更多