Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Abunga

macrumors newbie
Original poster
Jan 25, 2011
15
0
Hello, i am currently working through the necessary learning curves associated with all OBJ C newbies and have been looking at segmented controls.

I have been trying to practice by creating a simple web browser with both a url bar and a segmented control with 3 button that have hard coded urls. (A shortcut bar.)

The lessons that i have looked at do not explain how to hardcode the buttons. I am trying to use an if/else if set of statements. Where am i going wrong, i can only assume i have missed the boat somewhere along the way.

Code:
-(IBAction)urlShortcut:(id)sender {
	
	NSURL *urlDisplayItemTwo;
	NSString *outputURLtwo;
	NSString *urlCut;
	
	urlCut=[shortCuts titleForSegmentAtIndex:shortCuts.selectedSegmentIndex];	
	
	if (urlCut=@"Google") {
	
	outputURLtwo=[[NSString alloc] initWithFormat:@"http://www.google.co.uk"];
	urlDisplayItemTwo=[[NSURL alloc] initWithString:outputURLtwo];
	
	[pageDisplay loadRequest:[NSURLRequest requestWithURL:urlDisplayItemTwo]];
	}
	
	else if (urlCut=@"Rumors") {
		
		outputURLtwo=[[NSString alloc] initWithFormat:@"https://www.macrumors.com"];
		urlDisplayItemTwo=[[NSURL alloc] initWithString:outputURLtwo];
		
		[pageDisplay loadRequest:[NSURLRequest requestWithURL:urlDisplayItemTwo]];
	}		
	
	else if (urlCut=@"Ebay") {
		
		outputURLtwo=[[NSString alloc] initWithFormat:@"http://www.ebay.co.uk"];
		urlDisplayItemTwo=[[NSURL alloc] initWithString:outputURLtwo];
		
		[pageDisplay loadRequest:[NSURLRequest requestWithURL:urlDisplayItemTwo]];
	}

Do i need to initialise the segmented control when the view loads?

How do i ask for the value of each segment? I am only using urlCut as a variable similar to the variable used in a previous lesson from my book.

Probably simple, but i am getting there.

Thanks in advance, i hope.

Abunga.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.