Search code examples
iphoneobjective-cplistnsurl

iphone SDK :How to add more string after an static URL?


First...if no one can answer this question it's ok...

because I don't know how to ask this question in the correctly description

my program is get the plist data from URL and show it on the iphone tableview

My colleagues give me two URL to get the plist data

So I have two tableviews(tableview1,tableview2)

two URLs(URL1,URL2)

My tableview1 via URL1 get a plist1 ,and tableview1 has 3 contents in first 3 rows

ex.(row0 id1),(row1 id2),(row2 id3)

When I select row0 ,it will jump to tableview2 and with a title id1 on the navgation bar

so far is I can do...

but at tableview2 ,it need a URL like: www.URL2.php?id=1 =>that means...

I have to add my tableview title after URL2

to get the right plist related the id 1

my question is .......URL2 is static,how to make it like dynamic to get the right URL address ???

well.....first time I thought my colleagues will give me a data like array of array

But it's not...I never try use URL like dynamic...

This is code in the tableview1 to let me get the plist from URL

 NSURLRequest *theRequest=[NSURLRequest requestWithURL:appDelegate.URL1//I declare the  URL at appDelegate.m for some reasons...
                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy
                                              timeoutInterval:60.0];
      NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest
                           returningResponse:nil error:nil]; 
      NSString *listFile = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];   
              self.array = [listFile propertyList];//I parse the data from array to tablecview

and this is how I parse the title from Tableview1 to Tableview2

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

    TableView2 *tb2 = [[TableView2 alloc]init];
    tb2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    tb2.title = [[[array objectAtIndex:indexPath.row] valueForKey:@"name"]description];
    [self.navigationController pushViewController:tb2 animated:YES];   }

Any ideas ?

well ...if someone can answer this or give me a direction I will very appreciate

Great Thanks for All Reply and Answers !!!

Oh...one more thing,I can use ASIHTTPRequest to post a data

but I don't know how to get data after post ...?(is this help ?)


Solution

  • Assuming you have a string that you want to append to appDelegate.URL1 declared as:

    NSString *stringToAppend = @"whatever";
    

    Then you can produce a string containing the new URL:

    NSString *newURLAsString = [NSString stringWithFormat:@"%@%@",[appDelegate.URL1 absoluteString],stringToAppend];
    

    And an NSURL from this string:

    NSURL *newURL = [NSURL URLWithString:newURLAsString];
    

    And the NSURLRequest from that:

    NSURLRequest *theRequest=[NSURLRequest requestWithURL:newURL
                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                           timeoutInterval:60.0];