我想在用户单击NSToolbarItem
. 但是,在我的发件人中,我IBAction
没有得到一个NSView
实例,我觉得这很奇怪。
我可以显示 Popover(现在通过window.contentView
用作我的视图而不是工具栏的视图而错位 - 参见图片):
- (IBAction)accountIconTouched:(NSToolbarItem *)sender {
// NSView *view = [sender view]; // returns nil
NSView *view = self.window.contentView;
[self.accountPopover showRelativeToRect:[view bounds] ofView:view preferredEdge:NSMinYEdge];
}
那么我如何获得我的视图NSToolbarItem
以便弹出框出现。
这是我从控制台得到的错误:
2014-02-20 13:19:16.605 MyProject[42514:303] -[NSPopover showRelativeToRect:ofView:preferredEdge:]: nil view provided. You must supply a view.
2014-02-20 13:19:16.607 MyProject[42514:303] (
0 CoreFoundation 0x00007fff8086e41c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8bf33e75 objc_exception_throw + 43
2 AppKit 0x00007fff8cbf7b9c -[NSPopover showRelativeToRect:ofView:preferredEdge:] + 2214
3 MyProject 0x000000010000306d -[AppDelegate accountIconTouched:] + 253
4 AppKit 0x00007fff8d086e19 -[NSToolbarButton sendAction:to:] + 75
5 AppKit 0x00007fff8d086e68 -[NSToolbarButton sendAction] + 65
6 AppKit 0x00007fff8cb713d0 -[NSApplication sendAction:to:from:] + 327
7 AppKit 0x00007fff8cc3be9e -[NSToolbarItemViewer mouseDown:] + 4771
8 AppKit 0x00007fff8cb57d08 -[NSWindow sendEvent:] + 11296
9 AppKit 0x00007fff8caf6744 -[NSApplication sendEvent:] + 2021
10 Afloat 0x00000001007c2479 Afloat + 13433
11 AppKit 0x00007fff8c946a29 -[NSApplication run] + 646
12 AppKit 0x00007fff8c931803 NSApplicationMain + 940
13 MyProject 0x0000000100001912 main + 34
14 libdyld.dylib 0x00007fff8b1635fd start + 1
15 ??? 0x0000000000000003 0x0 + 3
)