Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your Code :</p> <pre><code>NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&amp;destination=%f,%f&amp;sensor=false",startPoint,midannotation.coordinate.latitude,midannotation.coordinate.longitude]; NSURL *googleRequestURL=[NSURL URLWithString:url]; dispatch_async(kBgQueue, ^{ NSData* data = [NSData dataWithContentsOfURL: googleRequestURL]; NSString *someString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // NSLog(@"data:%@",someString); NSError* error; NSMutableDictionary* parsedJson = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&amp;error]; NSArray *allkeys = [parsedJson allKeys]; for(int i = 0; i &lt; allkeys.count; i++){ if([[allkeys objectAtIndex:i] isEqualToString:@"routes"]){ arr = [parsedJson objectForKey:@"routes"]; dic = [arr objectAtIndex:0]; // NSLog(@"ALL KEYS FROM ROUTE: %@", [dic allKeys]); legs = [dic objectForKey:@"legs"]; // NSLog(@"legs array count %d", legs.count); for(int i = 0; i &lt; legs.count; i++){ stepsArr = [[legs objectAtIndex:i] objectForKey:@"steps"]; for (int i = 0; i &lt; stepsArr.count; i++) { NSLog(@"HTML INSTRUCTION %@", [[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"]); NSLog(@"############################"); NSMutableArray *detail=[[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"] ; } } } } }); </code></pre> <p>first you go to your .h file --></p> <pre><code>@property (nonatomic, strong) NSMutableArray * detailsArray; </code></pre> <p>In .m file --></p> <pre><code>@synthesize detailsArray; </code></pre> <p>replace this code </p> <pre><code>NSMutableArray *detail=[[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"] ; </code></pre> <p>by this --></p> <pre><code>self.detailsArray = [[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"]; # using table datasource methods - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.detailsArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.titleLabel.text = [self.detailsArray objectAtIndex: indexPath.row ]; return cell; } </code></pre> <p>}</p> <p>//<strong>Note</strong> Please set the delegate method of table , if you write the code programmatically means <code>tableView.delgate = self;</code></p> <p>Use this : </p> <pre><code>self.detaisArray = [[NSMutableArray alloc] init]; // Do any additional setup after loading the view, typically from a nib. NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&amp;destination=%f,%f&amp;sensor=false",startPoint,midannotation.coordinate.latitude,midannotation.coordinate.longitude]; NSURL *googleRequestURL=[NSURL URLWithString:url]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* data = [NSData dataWithContentsOfURL: googleRequestURL]; NSString *someString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // NSLog(@"data:%@",someString); NSError* error; NSMutableDictionary* parsedJson = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&amp;error]; NSArray *allkeys = [parsedJson allKeys]; for(int i = 0; i &lt; allkeys.count; i++){ if([[allkeys objectAtIndex:i] isEqualToString:@"routes"]){ NSArray *arr = [parsedJson objectForKey:@"routes"]; NSDictionary *dic = [arr objectAtIndex:0]; // NSLog(@"ALL KEYS FROM ROUTE: %@", [dic allKeys]); NSArray *legs = [dic objectForKey:@"legs"]; // NSLog(@"legs array count %d", legs.count); for(int i = 0; i &lt; legs.count; i++){ NSArray *stepsArr = [[legs objectAtIndex:i] objectForKey:@"steps"]; for (int i = 0; i &lt; stepsArr.count; i++) { NSLog(@"HTML INSTRUCTION %@", [[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"]); NSLog(@"############################"); [self.detaisArray addObject:[[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"] ]; if(i == legs.count-1){ self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 400) style:UITableViewStylePlain]; self.myTableView.delegate = self; self.myTableView.dataSource = self; [self.view addSubview:self.myTableView]; } } } } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload