NSSegmentedControl example

Coding Questions, IDE related or anything else

NSSegmentedControl example

Postby tanzanite » Mon Apr 05, 2010 11:41 pm

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.
tanzanite
 
Posts: 9
Joined: Thu Apr 01, 2010 5:46 am
Location: Mexico

Re: NSSegmentedControl example

Postby berndnoetscher » Tue Apr 06, 2010 10:37 am

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.
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: NSSegmentedControl example

Postby berndnoetscher » Wed Apr 07, 2010 12:02 pm

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
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: NSSegmentedControl example

Postby berndnoetscher » Wed Apr 07, 2010 12:10 pm

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

berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: NSSegmentedControl example

Postby tanzanite » Sat Apr 10, 2010 11:45 pm

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.
tanzanite
 
Posts: 9
Joined: Thu Apr 01, 2010 5:46 am
Location: Mexico


Return to Objective-Basic (Xcode 3)

Who is online

Users browsing this forum: No registered users and 1 guest

cron