NSButton setAction selector

后端 未结 4 1020
轮回少年
轮回少年 2021-01-13 20:13

I just want to add a NSButton with setAction Arguments.

NSRect frame = NSMakeRect(10, 40, 90, 40);  
NSButton* pushButton = [[NSButton alloc] initWithFrame:          


        
4条回答
  •  不要未来只要你来
    2021-01-13 20:20

    • .tag should be sufficient if your object have any integer uniqueID.
    • I use .identifier instead, since it support string based uniqueID.

    Example:

    ...
    for (index, app) in apps.enumerated() {
        let appButton = NSButton(title: app.title, target: self, action: #selector(appButtonPressed))
        appButton.identifier = NSUserInterfaceItemIdentifier(rawValue: app.guid)
    }
    
    ...
    @objc func appButtonPressed(sender: NSButton) {
        print(sender.identifier?.rawValue)
    }
    

提交回复
热议问题