Pariahware, Inc. Consulting iOS Apps Mac Apps Extend Xojo Home Contact Us Lessons: From Xojo to ObjC Christian's Soapbox Expect Updates Soon 22/10/13 00:50 Now that Xojo 2013 R3 is out, and Xcode 5 is no longer under NDA, expect more tutorials soon! Thank you for your support! 0 Comments PopUpMenus & ComboBoxes 13/03/13 14:24 Filed in: Xojo2ObjC The Xojo way. Start a new Xojo desktop project. Drag a PopUpMenu control and a ComboBox control onto the window. Name the PopUpMenu thePopUp and the ComboBox theCombo. I set both of my controls to 150 pixels. The window should look similar to this:
The first thing we need to do is create a new Boolean property so we wont see MsgBoxes when we launch the app:
Then in the windows open event, we set up our controls and the property:
In the PopUps Change event, we put the following notification code:
And, almost identical code in the ComboBoxs Change event:
Run the project and you will see MsgBoxes when you change the menu selection:
The Xcode way.
Launch Xcode, and choose File -> New Project. Choose OS X Application & Cocoa Application. Hit Next. Choose a name for your project, make sure Automatic Reference Counting (ARC) is checked and Document Based Application is unchecked. If you need help with this, check out the first entry about the PushButton which goes into great detail.
Choose the MainMenu.xib and drag in an NSPopUpButton and an NSComboBox. I made both of mine 150 points wide.
Go to your AppDelegate.m file, and under the #import line, type the @interface AppDelegate() and @end lines. Then put Xcode into split pane view so you have MainMenu.xib on one side and AppDelegate.m on the other. Control-Drag from each control to the @interface section. Name the NSPopUpButton thePopUp, and the NSComboBox theCombo. Again, if you need detailed help with this, check out the first entry about the PushButton which goes into great detail.
Now lets set up our controls in the applicationDidFinishLaunching event, just as we did previously. Notice the differences between filling the two controls with data.
In Objective-C, while the NSPopUpButton & NSComboBox look similar, they function differently. The NSPopUpButton will send us an IBAction when the selection has changed while the NSComboBox uses the delegate mechanism. After youve typed the above code, you are seeing the warning icon next to the _theCombo.delegate = self; line. Lets fix that by changing to the AppDelegate.h file; you can use keyboard shortcut Control-Command-UpArrow to flip back and forth between any associated .m & .h files. In the header, change the @interface line to look like the image below and flip back to your .m file. After a second or two the warning will disappear.
Lets add our action to receive NSPopUpButton selection changes. In split view, with AppDelegate.m on one side and MainMenu.xib on the other, select the NSPopUpButton on the window, Control-Drag from the NSPopUpButton to the .m file, when the PopUpWindow appears, change it to look like this and hit Connect:
Now that the action has been created, enter the code below. First we grab the popUps current text, then we display a dialog box, just as we did before.
Remember that the NSComboBox uses the delegate mechanism instead of the action mechanism, so we must invoke the proper method, which conveniently is called comboBoxSelectionDidChange. Notice we do essentially the same thing as with the NSPopUpButton, but the way we obtain the text is different:
Run the project, and:
0 Comments The Checkbox 25/02/13 03:26 Filed in: Xojo2ObjC The Xojo way. Start a new Xojo project. In the window, drag in a Checkbox & a Label. Title the Checkbox Toggle Me. Title the Label Checkbox is OFF, and set it so that the text is right justified. The window should look similar to this:
Double-click the checkbox and add the following code to the Action event:
Now in the Labels MouseDown, put this code:
Run the application. Toggling the checkbox on & off alternates between these two images:
Then, if you click on the Label:
The Xcode way.
Launch Xcode, and choose File -> New Project. Choose OS X Application & Cocoa Application. Hit Next. Choose a name for your project, make sure Automatic Reference Counting (ARC) is checked and Document Based Application is unchecked. Notice that there is no screenshot this week; were slowing removing training wheels.
Navigate to your MainMenu.xib, click on the window, and drag in a checkbox and a label. Title the checkbox Toggle Me & title the Label Checkbox is OFF. Like so:
Select the label & go to the Inspector Pane. Select the Attributes Inspector, and set the alignment to right- justified:
Select the checkbox & return to the Attributes Inspector. Set its State to Off, and check Allows Mixed:
Enter split pane view. Have your layout view on one side & your code view on the other. On the code side, select AppDelegate.m. Beneath the #import line, add @interface AppDelegate() and @end. Then control-drag from the checkbox to in between the two lines you just wrote. You will notice that the checkbox is actually an NSButton control. Call the checkbox checkbox. Do the same for the label and call it theLabel. It should look something like this:
Now, control-drag from the checkbox to the @implementation section. Give the method a name, and add the following code. I called my method checkboxToggled:
Run the app and check the checkbox.
0 Comments The Listbox, err, NSTableView 18/02/13 02:36 Filed in: Xojo2ObjC The Xojo way. Start a new Xojo project. In the window, drag in a Listbox & a PushButton. Label the PushButton Fill Table. In the Listbox property panel, set ColumnCount to 2 & ensure the HasHeading property is checked. The window should look similar to this:
In the windows Open Event, set up the Listbox header:
In the PushButtons Action Event, populate the Listbox:
Run the project, push the button, and...
The Xcode way.
Launch Xcode, and choose File -> New Project. Choose OS X Application, Cocoa Application as denoted by the arrows & hit Next.
Type tabletest in the first box as denoted by the arrow. Make sure Create Document-Based Application is unchecked and Use Automatic Reference Counting is checked. Click Next & Save the project.
Select MainMenu.xib and then the Window object. You will see a window in a grid layout, similar to Xojos.
Find the Table View control by using the filter in the lower-right hand corner, drag it and the Push Button into the window. Double-click the Push Button and label it Fill Table. Double-click each table header and label them Column 1 & Column 2 respectively.
After youve labeled the headers, click on the window to remove the highlight & return the window to its normal color. Now, in the white space of column 1, single-click 3 times to give the column focus.
In the property pane, select the Identity Inspector and name the Identity Identifier column1. Do the same for the second column and name it column2.
Put Xcode in split view with code view on the left side and the layout view on the right side. Select AppDelegate.h and modify the @interface to also be an NSTableViewDataSource as well as an NSTableViewDelegate. This allows the AppDelegate to provide data and other metrics to the NSTableView. This is different from Xojos built-in Listbox control and similar to Einhugurs DataGrid for Xojo.
Select AppDelegate.m. Beneath the #import line, add the @interface & @end lines.
Control-drag from the NSTableView between the @interface and name it theTable. Note, make sure youve selected the table section, below the header. Otherwise you will be creating an NSScrollView instead of the NSTableView.
After the @implementation, define two arrays and call them column1 & column2:
The next step is to tell the NSTableView to get its data from us, so, in applicationDidFinishLaunching:, add the following two lines:
Control-drag from the PushButton after applicationDidFinishLaunching: and add an action. After doing so, populate the 2 arrays signified by the first arrow and tell the TableView to populate as denoted by the second arrow.
We need to tell the TableView how many rows to display by adding the following routine. Note, we will be returning the number of elements in the array.
Now to populate the table with data. Add this method. When called, we ask the column which column it is by polling the identifier we set in layout mode.
And were done. Run the project & click the button. Success!
0 Comments (Wrapping) Text Fields 11/02/13 02:16 Filed in: Xojo2ObjC The Xojo way.
Start a new Xojo Desktop project and design the window to look like the image below. (2 Labels, 1 TextField, 1 TextArea, and 2 PushButtons)
Double-click the Push Me button and add the following code:
Now, double-click the Push Me, Too button and add the following code:
Run the project, add some text to each text control, and then test the two separate buttons:
The Xcode way. Launch Xcode, and choose File -> New Project. Choose OS X Application, Cocoa Application as denoted by the arrows & hit Next.
Type textfieldexamples in the first box as denoted by the arrow. Make sure Create Document-Based Application is unchecked and Use Automatic Reference Counting is checked. Click Next & Save the project.
Select MainMenu.xib and then the Window object. You will see a window in a grid layout, similar to Xojos.
Find the label control by using the filter in the lower-right hand corner and drag two labels into the window. Double-click each of them to change their text values.
Drag a Text Field, a Wrapping Text Field, and two Push Buttons. Make it look like the following image:
Now put the editor into split view/assistant mode:
On the left side, place your code by selecting the AppDelegate.m and keep the window layout on the right.
If you are having trouble getting the panes to look correct, click on the breadcrumbs and force them to look the way we want.
Although you could put upcoming information in the .h header file, the common thought these days is to only place public information into the header. So, right under the #import line of the .m file, add some private Interface code, like so:
Control-Drag from the Text Field to between your Interface, I named mine textField. This is how you will identify the Text Field in code. Do the same for the Wrapping Text Field. I called mine textArea.
Now add actions for the Push Buttons by similarly Control-Dragging from each button to the @implementation section:
Setup is done. Time to code!
Make your pushMeButton & pushMeTooButton actions look like this:
And test!
Type some text in textField and push its button to test:
Looks right! But, try typing in the multi-line field. Pressing the Return key doesnt add a new line, does it? Its not user-friendly, but you can type Opt-Return to add new-lines. Lets fix that. Select the header file:
Change the @interface line to read:
Youre really just adding , NSControlTextEditingDelegate before the >, which allows your app to respond to messages from TextFields.
Back to the .m (Implementation) file add the designated line to the applicationDidFinishLaunching event. This tells _textArea to send the messages to your app.
Finally, copy the following routine from Apples site and paste it into your file somewhere between @implementation & @end.
Run the project, test the field, and
0 Comments Quotes of Thanks Xojo2ObjC Oct 2013 Sep 2013 Aug 2013 Jul 2013 Jun 2013 May 2013 Apr 2013 Mar 2013Feb 2013 RSS Feed 2001-2014 Pariahware, Inc.