With SB, Ctrl-Drag has auto-generated viewcontroller available, but today we use Xib
Do not tick the use storyboards
This will happen after create:
See, there is no ready-made viewcontroller.
So we need to create our own ~
Do not create xib, because there is already a
Search the object library for Viewcontroller.
Just drag it over here.
Then connect the view to the Xib windows on the right
That's how xib and Rootviewcontroller are linked together.
Add this function in Rootviewcontroller, it will be called when the system loads the Xib (nib is xib after the program is packaged)
And then Ctrl-Drag to drag these, and here's something to watch out for--textview!
We can see that the TextView dragged out of the object library is actually composed of a scrollview and a TextView, TextView is the child control of the ScrollView, so, Want to associate TextView need to select TextView drag on the left, directly drag the associated is scrollview!!!
Complete Rootviewcontroller:
Define two string arrays to hold the option values for the Popupbutton and ComboBox:
var demopop: [String]!var democombo: [string]!
Perfect initialization, in awakefromnib:
Override Func awakefromnib () { //textfield demotextfield.stringvalue = "This is a TextField" //popupbutton Demopop = ["Pop1", "POP2", "POP3"] //Clear original item1, item2 demopopupbtn.removeallitems () Demopopupbtn.additemswithtitles (Demopop) demopopupbtn.selectitematindex (0) Democombo = ["Combo1", "Combo2 "," Combo3 "] democombobox.removeallitems () democombobox.additemswithobjectvalues (Democombo) Democombobox.selectitematindex (0) demodatepicker.datevalue = NSDate () }
Note that the Popupbutton add options with the Additemswithtitles, you can also add a additemwithtitles, the same kind of ComboBox.
To define a button click event:
@IBAction func gobtnclicked (sender:anyobject) {let popupstring = Demopopupbtn.stringvalue Let textfieldstring = Demotextfield.stringvalue let combostring = democombobox.stringvalue let sliderNum = Demoslider.doublevalue let datestring = demodatepicker.stringvalue demotextview.string = "U writed" \ ( textfieldstring) ' & Selected ' \ (popupstring) ' in Popupbutton & selected ' \ (combostring) ' in ComboBox & ' \ (slid Ernum) ' in sliders & selected ' \ (datestring) ' in datepicker! ' }
Run to see:
[MacOS] Some of the underlying controls