Page 1 of 1

NSSegmentedControl example

PostPosted: Mon Apr 05, 2010 11:41 pm
by tanzanite
Hi,

<ramble>
I'm new to objective-basic. So far, I see LOTS of possibilities and potential with it, and I really love the language. As a REALbasic programmer, I'm getting to understand how to hook the code up in Interface Builder, though it's not always obvious how. I like the much cleaner app appearance than those done in RB. In the future, I would like to see separate coding examples for each of the different controls. Between the examples available and Apple's Cocoa documentation, there are lots of things that are not obvious. Apple's documentation shows a heavy bent toward Objective-C, so how to do things here are not that clear. I have had success getting values from NSTextFields and NSButtons as well as putting values in the NSTextFields, but the NSSegmentedControl has me stumped :? . I also need to hook up an NSDatePicker to get a date value.
</ramble>

To the point:

I have been trying for days to write code to get the value of a segment or the index of an NSSegmentedControl in a normal application window, all with no luck. I have a function that gets activated when I click the control in the window, but I have been unable to access the values contained in it. Any example code and explanation for this and/or the NSDatePicker would be extremely appreciated.

Re: NSSegmentedControl example

PostPosted: Tue Apr 06, 2010 10:37 am
by berndnoetscher
I totally agree with your post. Examples for each available controls will follow. The next time you get stuck, please just ask in the forum to get support. :-)
Will post an example to your problem soon.

Re: NSSegmentedControl example

PostPosted: Wed Apr 07, 2010 12:02 pm
by berndnoetscher
The following code is connected to a NSSegmentedControl in a MainMenu.nib and is executed whenever the users presses this control.
It shows the selected index.

Code: Select all
IBAction setby(sender As id)

  Dim sgc As NSSegmentedControl = sender
  Alert(sgc.Selected()) ' returns the index of the selected item
 
End IBAction

Re: NSSegmentedControl example

PostPosted: Wed Apr 07, 2010 12:10 pm
by berndnoetscher
The following code is connected to a NSButton in a MainMenu.nib and is executed whenever the users presses this control.
It shows the selected index. A NSDatePicker is on a window as well.

NSDatePicker and NSDate are not yet declared in ObjB normally, but you can include it using declare statements.

Code: Select all

' add new Cocoa classes
Declare Class "NSDate"

Declare Class "NSDatePicker"
Declare Function "NSDatePicker" - (NSDate *)dateValue

IBOutlet odp As id ' outlet set in mainmenu.nib to the nsdatepicker!

IBAction showdate(sender As id)
 
  Dim dp As NSDatePicker = odp
  Dim d As NSDate = dp.dateValue()
  Alert(Info(d))
 
End IBAction


Re: NSSegmentedControl example

PostPosted: Sat Apr 10, 2010 11:45 pm
by tanzanite
This part of Cocoa functionality is not part of the official Objective-Basic language yet. It will be in the next versions.
The only way is to use Declare statements yet. Sorry about this.