objectValueForTableColumn
在 中选择行时出现异常,NSTableView
超出numberOfRowsInTableView
.
我认为这可能是由于使用单一方法控制多个表视图造成的,但我不知道该怎么做。
numberOfRowsInTableView
看起来像这样:
switch (tableView.tag) {
case 0:
return [itemMutableArray count];
break;
case 1:
return [categoryMutableArray count];
break;
case 2:
return [peopleMutableArray count];
break;
...
该objectValueForTableColumn
方法如下所示:
if (tableView.tag == 0) {
currentItem = [itemMutableArray objectAtIndex:row];
NSString *itemName = [currentItem valueForKey:@"title"];
return itemName;
}
if (tableView.tag == 1) {
currentCategory = [categoryMutableArray objectAtIndex:row];
NSString *catName = [currentCategory valueForKey:@"name"];
return catName;
}
如果我先点击出界,没问题。但是当我点击一行,然后点击越界时,我得到以下日志:
2013-06-18 13:40:16.169 TestApp[43953:303] -[MainWindowController tableViewSelectionDidChange:]
2013-06-18 13:40:16.169 TestApp[43953:303] Items Table View
2013-06-18 13:40:17.641 TestApp[43953:303] -[MainWindowController tableViewSelectionDidChange:]
2013-06-18 13:40:17.641 TestApp[43953:303] Items Table View
2013-06-18 13:40:17.642 TestApp[43953:303] *** -[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 6]
2013-06-18 13:40:17.643 TestApp[43953:303] (
0 CoreFoundation 0x00007fff8574e8ce __exceptionPreprocess + 174
1 libobjc.A.dylib 0x00007fff8b4e7f51 objc_exception_throw + 43
2 CoreFoundation 0x00007fff856ea615 -[__NSArrayM objectAtIndex:] + 245
3 TestApp 0x0000000100007508 -[MainWindowController tableViewSelectionDidChange:] + 760
4 CoreFoundation 0x00007fff856ffa63 _CFXNotificationPost + 3203
5 Foundation 0x00007fff8d25c24a -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
6 AppKit 0x00007fff8f7fdfc5 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 177
7 AppKit 0x00007fff8f7e3f2a -[NSTableView _enableSelectionPostingAndPost] + 406
8 AppKit 0x00007fff8fbbc7e0 -[NSTableView mouseDown:] + 5588
9 AppKit 0x00007fff8f780918 -[NSWindow sendEvent:] + 11303
10 AppKit 0x00007fff8f77af48 -[NSApplication sendEvent:] + 2021
11 AppKit 0x00007fff8f69c599 -[NSApplication run] + 646
12 AppKit 0x00007fff8f646563 NSApplicationMain + 940
13 TestApp 0x0000000100015982 main + 34
14 libdyld.dylib 0x00007fff8f28e60d start + 1
)