NSString to NSURL objects

Discussion in 'iOS Programming' started by vund0, May 10, 2010.

  1. vund0 macrumors newbie

    Joined:
    Oct 28, 2009
    #1
    Hello, I have an array that I populated with my plist file, which looks something like this:
    Code:
    <array>
       <string>http://www.apple.com</string>
       <string>http://www.google.com</string>
       <string>http://www.amazon.com</string>
    </array>
    
    So, I'm looking to convert these NSString objects to NSURL objects when I call them in my didSelectRowAtIndexPath method. Any ideas?


    This is what I have right now:
    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
         
         
         NSInteger row = [indexPath row];
         
         if (self.viewController == nil) {
              TemplateViewController *details = [[TemplateViewController alloc] initWithNibName:@"TemplateViewController" bundle:nil];
              self.viewController = details;
              [details release];
         }
         
         
         NSString *tempURLString = [tieroneurlArray objectAtIndex:row];
         NSURL *loadingUrl = [NSURL URLWithString:tempURLString];
         [tieroneurlArray addObject:loadingUrl];
         
         viewController.title = [NSString stringWithFormat:@"%@", [tieroneArray objectAtIndex:row]];
         
         [self.viewController setTableURL:[tieroneurlArray objectAtIndex:row]];     
         
         TemplateAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
         [delegate.templateNavController pushViewController:viewController animated:YES];
    }
    

    And this is how I load the array with the plist:
    Code:
    - (void)viewDidLoad {
        [super viewDidLoad];
         
         NSString *path = [[NSBundle mainBundle] pathForResource:@"tier1Names" ofType:@"plist"];
         tieroneArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
         
         NSString *tableURL = [[NSBundle mainBundle] pathForResource:@"tier1URL" ofType:@"plist"];     
         tieroneurlArray = [[NSMutableArray alloc] initWithContentsOfFile:tableURL];
    }
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    NSURL's URLWithString: should do the trick (which you're using). What seems to be the problem?
     

Share This Page