0
當在NSTableView
中選擇一行時,我在objectValueForTableColumn
中發現了一個異常,該行超出了numberOfRowsInTableView
。OSX - 使用多個表格 - 如何檢查單元格是否超出
我認爲這可能是由於使用單一的方法來控制多個表視圖,但我不知道該怎麼做。
的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
)
嗨,感謝您的評論。我已經爲我的問題添加了日誌。 –
對不起,我必須聽消息才能理解,而我錯過了這一點。我會按你的建議去做,然後回報。 –
除非有人認爲這是錯誤的,否則我會重新考慮我的架構併爲每個視圖創建單獨的ViewController。否則,我太過於拳擊自己了。 @Monolo,你的評論指引我採用正確的方法非常有幫助。如果你想寫你的建議作爲答案,我會接受它。 –