forked from LabPLC/DejateCaer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRutaViewController.m
111 lines (92 loc) · 4.68 KB
/
RutaViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// RutaViewController.m
// DejateCaer
//
// Created by Carlos Castellanos on 20/03/14.
// Copyright (c) 2014 Carlos Castellanos. All rights reserved.
//
#import "RutaViewController.h"
@interface RutaViewController ()
@end
@implementation RutaViewController
{
NSArray *segmentos;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 60, 320, self.view.frame.size.height)];
_tableView.dataSource=self;
_tableView.delegate=self;
_tableView.rowHeight=75;
_tableView.backgroundColor=[UIColor redColor];
[self.view addSubview:_tableView];
[super viewDidLoad];
[self planner];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)planner{
dispatch_async(dispatch_get_main_queue(), ^{
NSString *url= [NSString stringWithFormat:@"http://paw.dev.datos.labplc.mx/movilidad/transporte/planner/sunday/1394999266.json?lat_origin=%@&lon_origin=%@&lat_destination=%@&lon_destination=%@",_latitud_origen,_longitud_origen,_latitud_destino,_longitud_destino];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
if ([data length] >0 )
{
// NSLog(@"dentro del asyn");
NSString *dato=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSArray *listItems = [dato componentsSeparatedByString:@"<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/paw/datos/web/modules/movilidad/transporte.php:65) in <b>/home/paw/datos/web/outputs/Output_JSON.php</b> on line <b>23</b><br />"];
if ([listItems count]==1) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Mensaje" message:@"No tenemos una ruta que sugerirte :( lo sentimos" delegate:nil cancelButtonTitle:@"Aceptar" otherButtonTitles:nil, nil];
[alert show];
}else{
NSMutableString * miCadena = [NSMutableString stringWithString: [listItems objectAtIndex:1]];
NSData *data1 = [miCadena dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data1 options:NSJSONReadingAllowFragments error:nil];
NSArray *options= [jsonObject objectForKey:@"options"];
NSMutableDictionary *consulta=[[NSMutableDictionary alloc]init];
int aux=[[[options objectAtIndex:0]objectForKey:@"segments"] count];
//NSArray *aa=[options objectAtIndex:0];
if (aux!=0) {
consulta = [options objectAtIndex:0];
}
else{
consulta = [options objectAtIndex:1];
}
segmentos=[consulta objectForKey:@"segments"];
[_tableView reloadData];
}
}});
}
//http://paw.dev.datos.labplc.mx/movilidad/transporte/planner/sunday/1394999266.json?lat_origin=19.4527656&lon_origin=-99.1211996&lat_destination=19.4257912&lon_destination=-99.132911
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [segmentos count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"paso a celda");
// static NSString *simpleTableIdentifier = @"SimpleTableItem";
// eventCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customCell"];
UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"customCell"];
//UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
// NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"evento_cell" owner:self options:nil];
// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
// cell = [topLevelObjects objectAtIndex:0];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@",[[segmentos objectAtIndex:indexPath.row ] objectForKey:@"stop_origin_name"],[[segmentos objectAtIndex:indexPath.row ] objectForKey:@"stop_destination_name"]];
cell.detailTextLabel.text=[[[[segmentos objectAtIndex:indexPath.row ] objectForKey:@"trips"] objectAtIndex:0] objectForKey:@"agency_name"];//@"en Metro";
return cell;
}
@end