gpt4 book ai didi

swift - NSStatusItem 左键单击

转载 作者:行者123 更新时间:2023-11-28 06:18:16 27 4
gpt4 key购买 nike

首先:我是 Swift 开发的新手。
我正在使用 this 教程制作一个弹出窗口,当我点击我的顶部栏图标时会出现该弹出窗口。

所以我的 AppDelehgate 代码是:

func applicationDidFinishLaunching(_ aNotification: Notification){
print("START !");
if let button = statusItem.button {
button.image = NSImage(named: "logo");
button.action = Selector(("togglePopover:"));
//button.target = self;
}

popover.contentViewController = QuotesViewController(nibName: "QuotesViewController", bundle: nil);
}

func togglePopover(envoyeur: AnyObject?){
print("TOGGLE !");
if popover.isShown{
closePopover(sender: envoyeur)
} else {
showPopover(sender: envoyeur)
}
}

但从来没有“TOGGLE!”文本出现,事件不起作用。
我把“button.target = self;”发表评论,因为如果我不这样做,它就会崩溃。该事件似乎被触发,但我有一个错误:

START !
2017-06-08 15:55:29.116275+0200 MyWallpaper[7590:407660] -[MyWallpaper.AppDelegate togglePopover:]: unrecognized selector sent to instance 0x61000002a520
2017-06-08 15:55:29.122570+0200 MyWallpaper[7590:407660] [General] -[MyWallpaper.AppDelegate togglePopover:]: unrecognized selector sent to instance 0x61000002a520
2017-06-08 15:55:29.125822+0200 MyWallpaper[7590:407660] [General] (
0 CoreFoundation 0x00007fffb36f32cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffc84fe48d objc_exception_throw + 48
2 CoreFoundation 0x00007fffb3774f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fffb3665755 ___forwarding___ + 1061
4 CoreFoundation 0x00007fffb36652a8 _CF_forwarding_prep_0 + 120
5 libsystem_trace.dylib 0x00007fffc90153a7 _os_activity_initiate_impl + 53
6 AppKit 0x00007fffb18e1721 -[NSApplication(NSResponder) sendAction:to:from:] + 456
7 AppKit 0x00007fffb13c5cc4 -[NSControl sendAction:to:] + 86
8 AppKit 0x00007fffb18ceff7 -[NSStatusBarButtonCell _sendActionFrom:] + 155
9 libsystem_trace.dylib 0x00007fffc90153a7 _os_activity_initiate_impl + 53
10 AppKit 0x00007fffb13c4426 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2481
11 AppKit 0x00007fffb1408272 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 798
12 AppKit 0x00007fffb18cea1f -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 327
13 AppKit 0x00007fffb13c2ddb -[NSControl mouseDown:] + 832
14 AppKit 0x00007fffb1a5d24f -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 6341
15 AppKit 0x00007fffb1a59a6c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 1942
16 AppKit 0x00007fffb1a58f0a -[NSWindow(NSEventRouting) sendEvent:] + 541
17 AppKit 0x00007fffb18d26d1 -[NSStatusBarWindow sendEvent:] + 581
18 AppKit 0x00007fffb18dd681 -[NSApplication(NSEvent) sendEvent:] + 1145
19 AppKit 0x00007fffb1158427 -[NSApplication run] + 1002
20 AppKit 0x00007fffb1122e0e NSApplicationMain + 1237
21 MyWallpaper 0x00000001000039ad main + 13
22 libdyld.dylib 0x00007fffc8de3235 start + 1
23 ??? 0x0000000000000003 0x0 + 3
)

最佳答案

使用 Swift #selector 语法

button.action = #selector(togglePopover(_:)) // or just #selector(togglePopover)

关于swift - NSStatusItem 左键单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44437800/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com