Segmented Control Confusion!

Discussion in 'iOS Programming' started by Abunga, Feb 15, 2011.

  1. Abunga macrumors newbie

    Abunga

    Joined:
    Jan 25, 2011
    #1
    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:@"http://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.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    First of all, = is an assignment operator, not an equality one (i.e. ==).

    Second, == is not the proper way to compare NSStrings. NSString has an instance method expressly created for this purpose.
     

Share This Page