removeobjectAtIndex:使索引为-1;

时间:2015-05-14 01:19:07

标签: xcode macos cocoa nsmutablearray nstableview

我有一个名为tableArray的数组填充的NSTableView。我有一个按钮,应该从数组中删除所选项目。在我的removeItem:方法:

[tableArray removeObjectAtIndex:[tableView selectedRow];
[tableView reloadData];

但我收到错误:

2015-05-13 18:16:45.283 FileShedb1.0[979:303] *** -[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 0]
2015-05-13 18:16:45.288 FileShedb1.0[979:303] (
    0   CoreFoundation                      0x00007fff8d35ff56 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff93119d5e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8d2ed392 -[__NSArrayM objectAtIndex:] + 274
    3   FileShedb1.0                        0x00000001000028a9 -[MPOMainWindowController tableViewSelectionDidChange:] + 201
    4   Foundation                          0x00007fff8cca0d0e __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
    5   CoreFoundation                      0x00007fff8d3087ba _CFXNotificationPost + 2634
    6   Foundation                          0x00007fff8cc8cfc3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
    7   AppKit                              0x00007fff8ab10049 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
    8   AppKit                              0x00007fff8aae6b0a -[NSTableView _enableSelectionPostingAndPost] + 425
    9   AppKit                              0x00007fff8aadcd75 -[NSTableView _tileAndRedisplayAll] + 358
    10  FileShedb1.0                        0x00000001000027bc -[MPOMainWindowController removeFile:] + 188
    11  CoreFoundation                      0x00007fff8d34f70d -[NSObject performSelector:withObject:] + 61
    12  AppKit                              0x00007fff8aaa98ca -[NSApplication sendAction:to:from:] + 139
    13  AppKit                              0x00007fff8aaa97fe -[NSControl sendAction:to:] + 88
    14  AppKit                              0x00007fff8aaa9729 -[NSCell _sendActionFrom:] + 137
    15  AppKit                              0x00007fff8aaa8bec -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
    16  AppKit                              0x00007fff8ab28b74 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
    17  AppKit                              0x00007fff8aaa77f6 -[NSControl mouseDown:] + 786
    18  AppKit                              0x00007fff8aa72c98 -[NSWindow sendEvent:] + 6306
    19  AppKit                              0x00007fff8aa0c3a5 -[NSApplication sendEvent:] + 5593
    20  AppKit                              0x00007fff8a9a2a0e -[NSApplication run] + 555
    21  AppKit                              0x00007fff8ac1eeac NSApplicationMain + 867
    22  FileShedb1.0                        0x00000001000014c2 main + 34
    23  FileShedb1.0                        0x0000000100001494 start + 52
)

任何人都知道我为什么会收到错误?

1 个答案:

答案 0 :(得分:1)

如果未选择任何行,selectedRow行将返回-1。检查一下。

Checkout apple's documentation