|
|
New NSButton-Thingy announced at WWDC
|
|
|
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status:
Offline
|
|
Originally posted by Chuckit:
No, NSSegmentedControl is not available from Interface Builder.
Bah! Fascist IB developer bastards!
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Location: New York City
Status:
Offline
|
|
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];
}
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Location: New York City
Status:
Offline
|
|
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
That builds and works just fine, weird.
Thanks for the project,
Oliver
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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)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.
Is this possible? Sample code is appreciated.
Thanks,
Oliver
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Sep 2000
Location: UK
Status:
Offline
|
|
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).
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Sep 2000
Location: UK
Status:
Offline
|
|
Code:
int clickedSegmentTag = [[sender cell] tagForSegment:clickedSegment];
I didn't catch that because Safari doesn't have gcc built-in yet
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Location: New York City
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Location: New York City
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2002
Location: New York City
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|