2017-06-08 3 views
1

Erstens: Ich bin neu mit Swift Entwicklung.
Ich benutze this Tutorial, um ein Popup zu erstellen, das erscheint, wenn ich auf meine obere Leiste Symbol klicke.
NSStatusItem links klicken

Also mein AppDelehgate Code ist:

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) 
    } 
} 

aber nie die "TOGGLE!" Text erscheint, das Ereignis funktioniert nicht.
Ich habe die "button.target = self;" in Kommentar, weil es abstürzt, wenn ich es nicht mache. Das Ereignis scheint die trigged sein, aber ich habe einen Fehler bekommt:

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 
) 

Antwort

1

die #selector Syntax Swift Verwenden

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

Danke, aber gibt mir: Die Verwendung von ungelöster Kennung 'togglePopover':/ – Antoine

+0

Try die andere Syntax in der bearbeiteten Antwort. – vadian

+0

Danke, es funktioniert: D – Antoine

Verwandte Themen