pariah ware

29
Pariahware, Inc. iOS Freelancer, iOS Consultant 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

Upload: virusyadav

Post on 28-Dec-2015

34 views

Category:

Documents


0 download

DESCRIPTION

v

TRANSCRIPT

Page 1: Pariah Ware

Pariahware, Inc.

iOS Freelancer, iOS Consultant

Pariahware, Inc. Consulting iOS Apps Mac Apps Extend Xojo

Home Contact Us Lessons: From Xojo to ObjC Christian's Soapbox

Expect Updates Soon22/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 & ComboBoxes13/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:

Page 2: Pariah Ware

The first thing we need to do is create a new Boolean property so we won’t see MsgBoxes when we launch the app:

Then in the window’s open event, we set up our controls and the property:

In the PopUp’s Change event, we put the following notification code:

And, almost identical code in the ComboBox’s Change event:

Page 3: Pariah Ware

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.

Page 4: Pariah Ware

Now let’s 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 you’ve typed the above code, you are seeing the “warning” icon next to the _theCombo.delegate = self; line. Let’s 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.

Let’s 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:

Page 5: Pariah Ware

Now that the action has been created, enter the code below. First we grab the popUp’s 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:

Page 6: Pariah Ware

Run the project, and:

0 Comments

The Checkbox25/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:

Page 7: Pariah Ware

Now in the Label’s MouseDown, put this code:

Run the application. Toggling the checkbox on & off alternates between these two images:

Page 8: Pariah Ware

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; we’re 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”:

Page 9: Pariah Ware

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.

Page 10: Pariah Ware

0 Comments

The Listbox, err, NSTableView18/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:

Page 11: Pariah Ware

In the window’s Open Event, set up the Listbox header:

In the PushButton’s Action Event, populate the Listbox:

Run the project, push the button, and...

Page 12: Pariah Ware

The Xcode way.

Launch Xcode, and choose File -> New Project. Choose OS X Application, Cocoa Application as denoted by the arrows & hit Next.

Page 13: Pariah Ware

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.

Page 14: Pariah Ware

Select “MainMenu.xib” and then the “Window” object. You will see a window in a grid layout, similar to Xojo’s.

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.

Page 15: Pariah Ware

After you’ve 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.

Page 16: Pariah Ware

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 Xojo’s built-in Listbox control and similar to Einhugur’s DataGrid for Xojo.

Page 17: Pariah Ware

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 you’ve 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:

Page 18: Pariah Ware

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.

Page 19: Pariah Ware

And we’re done. Run the project & click the button. Success!

0 Comments

(Wrapping) Text Fields11/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)

Page 20: Pariah Ware

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:

Page 21: Pariah Ware

The Xcode way.Launch Xcode, and choose File -> New Project. Choose OS X Application, Cocoa Application as denoted by the arrows & hit Next.

Page 22: Pariah Ware

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.

Page 23: Pariah Ware

Select “MainMenu.xib” and then the “Window” object. You will see a window in a grid layout, similar to Xojo’s.

Find the label control by using the filter in the lower-right hand corner and drag two labels into the window.

Page 24: Pariah Ware

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.

Page 25: Pariah Ware

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”.

Page 26: Pariah Ware

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:

Page 27: Pariah Ware

Looks right! But, try typing in the multi-line field. Pressing the “Return” key doesn’t add a new line, does it? It’s not user-friendly, but you can type “Opt-Return” to add new-lines. Let’s fix that.Select the header file:

Change the @interface line to read:

You’re 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.

Page 28: Pariah Ware

Finally, copy the following routine from Apple’s site and paste it into your file somewhere between @implementation & @end.

Page 29: Pariah Ware

Run the project, test the field, and…

0 CommentsQuotes of Thanks Xojo2ObjCOct 2013Sep 2013Aug 2013Jul 2013Jun 2013May 2013Apr 2013Mar 2013 Feb 2013 RSS Feed© 2001-2014 Pariahware, Inc.