我正在 Xcode5 中为 OSX 开发应用程序
我想在用户结束编辑 tableview 单元格后显示一个弹出框我在做什么如下:
-(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
if ([[tableColumn.headerCell stringValue] isEqualToString:@"CUENTAS DE ACTIVO"]) {
[arrayOne replaceObjectAtIndex:row withObject:object];
}
else{
[arrayTwo replaceObjectAtIndex:row withObject:object];
}
[self.popoverClasifCuentas showRelativeToRect:[tableView bounds] ofView:[[[tableColumn dataCell] objectAtIndex:row] view] preferredEdge:NSMaxYEdge];
}
当我运行它时,我收到以下错误:
-[NSTextFieldCell objectAtIndex:]: unrecognized selector sent to instance 0x6080002a2a60
2014-06-09 19:17:18.424 eAccounting[2976:303] Exception detected while handling key input.
2014-06-09 19:17:18.424 eAccounting[2976:303] -[NSTextFieldCell objectAtIndex:]: unrecognized selector sent to instance 0x6080002a2a60
2014-06-09 19:17:18.426 eAccounting[2976:303] (
0 CoreFoundation 0x00007fff9428625c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8c47ee75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff9428912d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff941e4322 ___forwarding___ + 1010
4 CoreFoundation 0x00007fff941e3ea8 _CF_forwarding_prep_0 + 120
5 eAccounting 0x000000010000a88a -[EdicionDeCuentasWC tableView:setObjectValue:forTableColumn:row:] + 922
6 AppKit 0x00007fff955699f5 -[NSTableView textDidEndEditing:] + 487
7 CoreFoundation 0x00007fff94254e0c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
8 CoreFoundation 0x00007fff941488dd _CFXNotificationPost + 2893
9 Foundation 0x00007fff8d58c7ba -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
10 AppKit 0x00007fff9512582d -[NSTextView(NSPrivate) _giveUpFirstResponder:] + 438
11 AppKit 0x00007fff95173aec -[NSTextView(NSKeyBindingCommands) insertNewline:] + 239
12 AppKit 0x00007fff950f6c2f -[NSResponder doCommandBySelector:] + 71
13 AppKit 0x00007fff9512410a -[NSTextView doCommandBySelector:] + 196
14 AppKit 0x00007fff950f6151 -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] + 1392
15 AppKit 0x00007fff951151c2 -[NSTextInputContext handleEvent:] + 845
16 AppKit 0x00007fff950f49dd -[NSView interpretKeyEvents:] + 180
17 AppKit 0x00007fff95114d6d -[NSTextView keyDown:] + 658
18 AppKit 0x00007fff950c156b -[NSWindow sendEvent:] + 1843
19 AppKit 0x00007fff95062b32 -[NSApplication sendEvent:] + 3395
20 AppKit 0x00007fff94eb2a19 -[NSApplication run] + 646
21 AppKit 0x00007fff94e9d7a3 NSApplicationMain + 940
22 eAccounting 0x000000010000c3e2 main + 34
23 libdyld.dylib 0x00007fff899a55fd start + 1
24 ??? 0x0000000000000003 0x0 + 3
它不能正常工作,我暂时在我的 NSTableView 顶部添加了一个隐藏按钮,为它设置了一个 IBOutlet(popoverButton)并遵循 IBAction:
- (IBAction)showPopover:(id)sender {
ClasificacionDeCuentasVC *vc = (ClasificacionDeCuentasVC *) self.popoverClasifCuentas.contentViewController;
vc.delegate = self;
[self.popoverClasifCuentas showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxYEdge];
}
然后我在我的 NSTableView 方法上替换了最后一句话:
-(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
if ([[tableColumn.headerCell stringValue] isEqualToString:@"CUENTAS DE ACTIVO"]) {
[arrayOne replaceObjectAtIndex:row withObject:object];
}
else{
[arrayTwo replaceObjectAtIndex:row withObject:object];
}
[self.popoverButton performClick:tableView];
}
它可以工作,但在 NSButton 的位置显示我的弹出窗口,如下所示:
我想在我的 tableview 单元格的位置显示它,怎么做???