NSString to NSURL objects

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

  1. vund0 macrumors newbie

    Oct 28, 2009
    Hello, I have an array that I populated with my plist file, which looks something like this:
    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:
    - (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:
    - (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


    Staff Member

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

Share This Page