Monday, 15 September 2014

osx - How to let multiple components/controls share similar action in Xcode -


I'm using Xcode 6 and Swift to develop an OS X app, not iOS. Suppose we have two toggle buttons and each one controls Cambodia. Press the button every time, it will enable or disable Cambodia in control. I can definitely set different actions for each button. Since I have ten buttons, this approach contains many unnecessary code.

  @Inbooting Function Click BTN1 (Sender: NSBitton) {If Combo Box 1.Nenad == True {COMBOBOX 1.Annal = False; } And {combobox1.enabled = true; }} @Ebooting Function Click BTN2 (Sender: NSBitton) {// same code for combobox2}  

Is there any way to make it easy, such as the different sender, VB Is NET similar?

Update: I found an uncompromising solution for this

I now control / drag two buttons in one action in ViewController.swift And also give a different tag to those two buttons Button1.tag = 1, button2.tag = 2. The code now looks,

  // button1.tag = 1, button2.tag = 2. @Ebtension Funk Click Button (Sender: NSButton) {Switch (SendTag) {Case 0: Combobox 1. Enabled =! Combobox 1 capable; break; Case 1: Combobox 2. Enabled =! Combobox 2 capable; break; Default: Break; }}  

This resolves a part of my problem Next, I'm surprised that there is no way to access / search through controls / references, for example a string or Tag or anything name Pseudo code would like the following,

  // button1.tag = 1, button2.tag = 2. @ ebouting function click button (sender: NSButton) {// pseudo code code box [button.tag] .enabled =! Combobox [button.tag] capable; }  

be able to bind you to all NSButton Control the events to control the same button: ( NSComboBox ): Method You can do this via the interface builder or via the setAction: < / Code> can be obtained through the method.

Selectors in swift are just strings, like "button is clicked:" , but I wrap them in the selector for clarity in the initials I like (like selector ("button clicked:") ).


No comments:

Post a Comment