Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > New NSButton-Thingy announced at WWDC

New NSButton-Thingy announced at WWDC
Thread Tools
macrophyllum
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Dec 10, 2003, 11:47 AM
 
Hi,

At WWDC in June Apple said they would make there switcher button thing class (like the one that lets you select which view you want in the Finder) public with Panther. They even said they were going to have "contest" to try and give it an appropriate name. I can't seem to find any details on it.

Anyone know anything about this?
     
Diggory Laycock
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Dec 10, 2003, 12:08 PM
 
Ta-Da:

http://developer.apple.com/documenta...gmentedControl

"Switcher Thing" became "NSSegmentedControl" - hmm - makes me think of Tangerines....
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Dec 10, 2003, 05:00 PM
 
Strangely, it didn't make it into Interface Builder for the 10.3 release, but you can still use it by setting it up programmatically.

Geez, you'd think if they were having a contest, a better sounding name would have come out of it.
Rick Roe
icons.cx | weblog
     
macrophyllum  (op)
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Dec 10, 2003, 10:17 PM
 
Thanks guys!
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Dec 11, 2003, 12:27 AM
 
Originally posted by Rickster:
Strangely, it didn't make it into Interface Builder for the 10.3 release, but you can still use it by setting it up programmatically.

Geez, you'd think if they were having a contest, a better sounding name would have come out of it.
Actually, I think it's an excellent name. Describes what it does nicely.
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 18, 2003, 06:22 PM
 
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 18, 2003, 06:48 PM
 
I just wanted to try out NSSegmentedControl and made a test app for it. Heres the code:

- (void)awakeFromNib
{
[segControl setSegmentCount:4];
[segControl setWidth:260 forSegment:0];
[segControl setWidth:260 forSegment:1];
[segControl setWidth:260 forSegment:2];
[segControl setWidth:260 forSegment:3];
[segControl setLabel:@"Import" forSegment:0];
[segControl setLabel:@"Organize" forSegment:1];
[segControl setLabel:@"Edit" forSegment:2];
[segControl setLabel:@"Book" forSegment:3];
}

Now the code builds fine, and the nib is all setup.

But, for some strange, strange reason OS X decides to render it like this:

(Keep in mind the NSSegmentedControl view takes up the whole window:



Any ideas?
     
Turias
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Dec 18, 2003, 06:53 PM
 
Originally posted by iOliverC:
I just wanted to try out NSSegmentedControl and made a test app for it.
I haven't used an NSSegmentedControl, yet, but isn't it possible to do everything you are doing through the nib?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 18, 2003, 07:03 PM
 
Originally posted by Turias:
I haven't used an NSSegmentedControl, yet, but isn't it possible to do everything you are doing through the nib?
No, NSSegmentedControl is not available from Interface Builder.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Turias
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Dec 18, 2003, 07:05 PM
 
Originally posted by Chuckit:
No, NSSegmentedControl is not available from Interface Builder.
Bah! Fascist IB developer bastards!
     
zachs
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Dec 19, 2003, 01:50 AM
 
Worked fine for me:



Here's the code:

Code:
- (void)awakeFromNib { [segControl setSegmentCount:4]; [segControl setWidth:110 forSegment:0]; [segControl setWidth:110 forSegment:1]; [segControl setWidth:110 forSegment:2]; [segControl setWidth:110 forSegment:3]; [segControl setLabel:@"Import" forSegment:0]; [segControl setLabel:@"Organize" forSegment:1]; [segControl setLabel:@"Edit" forSegment:2]; [segControl setLabel:@"Book" forSegment:3]; }
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 19, 2003, 06:26 AM
 
This is very weird, I have dragged over the NSSegmentedControl/Cell headers from the AppKit.framework, I am using the same exact code as you. Do you put any resizing springs on it?
     
zachs
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Dec 19, 2003, 02:27 PM
 
Here's my project. Build it and see if it works.

Download Here
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 19, 2003, 02:47 PM
 
That builds and works just fine, weird.

Thanks for the project,
Oliver
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 19, 2003, 02:53 PM
 
I don't quite get how to do actions, this is the code from the Apple document:

- (void)awakeFromNib
{
[segControl setSegmentCount:3];
[[segControl cell] setTag:0 forSegment:0];
[[segControl cell] setTag:1 forSegment:1];
[[segControl cell] setTag:2 forSegment:2];
[segControl setTarget:self];
[segControl setAction:@selector(segControlClicked];
}

- (IBAction)segControlClickedid)sender
{
int clickedSegment = [sender selectedSegment];
int clickedSegmentTag = [[sender cell] tagForSegment:selectedSegment];
}

In my segmented control, I have 2 cells. In one cell is a back button and the other forward. So I want to use the action goBack: for the first segment and goForward for the second segment.

Is this possible? Sample code is appreciated.

Thanks,
Oliver
     
calumr
Forum Regular
Join Date: Sep 2000
Location: UK
Status: Offline
Reply With Quote
Dec 19, 2003, 03:09 PM
 
Originally posted by iOliverC:
Code:
- (IBAction)segControlClicked:(id)sender { int clickedSegment = [sender selectedSegment]; int clickedSegmentTag = [[sender cell] tagForSegment:selectedSegment]; }
In my segmented control, I have 2 cells. In one cell is a back button and the other forward. So I want to use the action goBack: for the first segment and goForward for the second segment.
Code:
- (IBAction)segControlClicked:(id)sender { int clickedSegment = [sender selectedSegment]; int clickedSegmentTag = [[sender cell] tagForSegment:selectedSegment]; switch (clickedSegmentTag) { case 0: [self goBack:sender]; break; case 1: [self goForward:sender]; break; default: NSLog(@"You clicked in a non-existent segment!!!"); break; } }
You could just switch on the clickedSegment, but using the tag is a bit more correct (in case you ever want to switch the order of the cells).
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 19, 2003, 05:15 PM
 
I just tried your code, and got the following errors:

selectedSegment undeclared (first use in function)

its for this code:

int clickedSegmentTag = [[sender cell] tagForSegment:selectedSegment];

Any ideas?
     
calumr
Forum Regular
Join Date: Sep 2000
Location: UK
Status: Offline
Reply With Quote
Dec 19, 2003, 06:19 PM
 
Code:
int clickedSegmentTag = [[sender cell] tagForSegment:clickedSegment];
I didn't catch that because Safari doesn't have gcc built-in yet
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 20, 2003, 05:56 AM
 
Heres all my code, I can't understand why selectedSegment is undeclared.

Code:
- (void)awakeFromNib { [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]]; [[segControl cell] setTrackingMode:NSSegmentSwitchTrackingMomentary]; [segControl setSegmentCount:2]; [segControl setWidth:0 forSegment:0]; [segControl setWidth:0 forSegment:1]; [[segControl cell] setTag:0 forSegment:0]; [[segControl cell] setTag:1 forSegment:1]; [segControl setTarget:self]; [segControl setAction:@selector(segControlClicked:)]; } - (IBAction)segControlClicked:(id)sender { int clickedSegment = [sender selectedSegment]; int clickedSegmentTag = [[sender cell] tagForSegment:selectedSegment]; switch (clickedSegmentTag) { case 0: [self goBack:nil]; break; case 1: [self goForward:nil]; break; default: NSLog(@"You clicked in a non-existent segment!!!"); break; } }
One more thing, the goForward and goBack, needs to be the target of webView. How can I set this in the segControlClicked: method?

Thanks,
Oliver
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 20, 2003, 07:09 AM
 
Originally posted by iOliverC:
Heres all my code, I can't understand why selectedSegment is undeclared.
As calumr said, selectedSegment is undeclared. The variable is called clickedSegment.

One more thing, the goForward and goBack, needs to be the target of webView. How can I set this in the segControlClicked: method?
I don't know what you mean here. WebViews don't have targets; they aren't NSControls.
( Last edited by Chuckit; Dec 20, 2003 at 07:16 AM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
zachs
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Dec 20, 2003, 04:49 PM
 
Try this:

Code:
- (void)awakeFromNib { [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]]; [[segControl cell] setTrackingMode:NSSegmentSwitchTrackingMomentary]; [segControl setSegmentCount:2]; [segControl setWidth:0 forSegment:0]; [segControl setWidth:0 forSegment:1]; [[segControl cell] setTag:0 forSegment:0]; [[segControl cell] setTag:1 forSegment:1]; [segControl setTarget:self]; [segControl setAction:@selector(segControlClicked:)]; } - (IBAction)segControlClicked:(id)sender { int clickedSegment = [sender selectedSegment]; int clickedSegmentTag = [[sender cell] tagForSegment:clickedSegment]; switch (clickedSegmentTag) { case 0: [webView goBack:nil]; break; case 1: [webView goForward:nil]; break; default: NSLog(@"You clicked in a non-existent segment!!!"); break; } }
I changed "[self goForward:nil];" to "[webView goForward:nil];", and it worked fine.
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 21, 2003, 08:33 AM
 
Worked great :-)

And I have yet another question for you all :-)

Pardon my newbiness, but in such apps as Help Center, the button is faded out when you cannot go forward. I know WebKit has this built in for normal images, but it seems not for NSSegmentedControl. How would I go about fading and disabling the button appropriately for a Web View?

Thanks for all the help,

Oliver
     
zachs
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Dec 21, 2003, 10:07 AM
 
Try this:

Code:
#import "Controller.h" #import <WebKit/WebKit.h> @implementation Controller - (void)awakeFromNib { [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yahoo.com"]]]; [[navControl cell] setTrackingMode:NSSegmentSwitchTrackingMomentary]; [navControl setSegmentCount:2]; [navControl setWidth:0 forSegment:0]; [navControl setWidth:0 forSegment:1]; [navControl setEnabled:[webView canGoBack] forSegment:0]; [navControl setEnabled:[webView canGoForward] forSegment:1]; [navControl setImage:[NSImage imageNamed:@"BackAdorn"] forSegment:0]; [navControl setImage:[NSImage imageNamed:@"ForwardAdorn"] forSegment:1]; [[navControl cell] setTag:0 forSegment:0]; [[navControl cell] setTag:1 forSegment:1]; [navControl setTarget:self]; [navControl setAction:@selector(navControlClicked:)]; } - (IBAction)navControlClicked:(id)sender { int clickedSegment = [sender selectedSegment]; int clickedSegmentTag = [[sender cell] tagForSegment:clickedSegment]; switch (clickedSegmentTag) { case 0: [webView goBack:nil]; break; case 1: [webView goForward:nil]; break; default: NSLog(@"You clicked in a non-existent segment!!!"); break; } } - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { NSLog(@"webView:didFinishLoadForFrame: where sender=%@", sender); // Only report feedback for the main frame. if (frame == [sender mainFrame]){ [navControl setEnabled:[sender canGoBack] forSegment:0]; [navControl setEnabled:[sender canGoForward] forSegment:1]; } } @end
Make sure to link to the WebKit framework! ;)
Also, change "navControl" to whatever your NSSegmentedControl is called.
     
iOliverC
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Dec 21, 2003, 10:32 AM
 
Thanks for all the code I really appreciate it .

One thing though, I tried your code and imported the WebKit framework and all builds well. But when I click a link in the Web View, and it goes to the next page, back is still disabled. Any ideas?
     
zachs
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Dec 21, 2003, 04:32 PM
 
Originally posted by iOliverC:
Thanks for all the code I really appreciate it .

One thing though, I tried your code and imported the WebKit framework and all builds well. But when I click a link in the Web View, and it goes to the next page, back is still disabled. Any ideas?
Whoops!
Yeah, add this to your -awakeFromNib:

Code:
[webView setFrameLoadDelegate:self]; [webView setResourceLoadDelegate:self];
That should do it.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:19 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,