-4

I have maultiple json :

http://privatereisen.com/dok/TV/pays/italie/json/chaine0.json
http://privatereisen.com/dok/TV/pays/italie/json/chaine1.json...... etc

And a table with different channels. Chaine0 is for the first row from UITableView. How can I write in didSelectRowAtIndexPath json for each channel?

This is how i write for the first json:

NSURL *url = [NSURL URLWithString:@"http://privatereisen.com/"];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

[httpClient postPath:@"dok/TV/pays/italie/json/chaine0.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
Yuyutsu
  • 2,509
  • 22
  • 38
Georgiana
  • 127
  • 3
  • 11

3 Answers3

0
 NSString *path=[NSString stringWithFormat :@"dok/TV/pays/italie/json/chaine%d.json",indexPath.row];

[httpClient postPath:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
Georgiana
  • 127
  • 3
  • 11
0

I assume you have a collection based on which you populate your table view.

The tableView:didSelectRowAtIndexPath: method clearly tells you the indexPath of the selected cell.

You need to use that to identify the object based on which the cell was populated (If there's a single section, the table view is usually populated based on an NSArray, so you can get your object with id object = self.array[indexPath.row];)

After you got your object, you do whatever you want with it.


Since in your case there's a direct correlation between the indexPath.row and your object, you can do:

NSString *path = [NSString stringWithFormat :@"dok/TV/pays/italie/json/chaine%@.json",@(indexPath.row)];

PS: I recommend using %@ and converting your NSInteger to an NSNumber instead of %d since %d means 32-bit int, but an NSInteger is a 64-bit int on 64-bit devices.

Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
0

First you have to find the which row is clicked. For that you have to find the indexPath of that row.

NSString *selectingRow=[arrayData objectAtIndex:indexPath.row];
NSLog(@"Selected Object is %@",selectingRow);

Now you can pass any variable to your server(to recognize the specific row details). You have to hit your server and get the details of that row.

vishnu
  • 715
  • 9
  • 20
  • The variable `selectingRow` won't be the `Selected Row`. `indexPath.row` is the selected row. Your variable will be the object associated with the selected row or the selected object for short. – Lord Zsolt Dec 22 '14 at 14:08
  • I am not selecting any variable. I am selecting only row. From row you have to get the variable orderIdClicked = [refinedOrderIDArray objectAtIndex:indexPath.row]; – vishnu Dec 22 '14 at 14:18
  • The log is incorrect `NSLog(@"Selected Row is %@",selectingRow);`. It should be something like `NSLog(@"Selected Object is %@",selectingRow);` – Lord Zsolt Dec 22 '14 at 14:19