- (void)viewDidLoad {
self.detailView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
self.detailView.dataSource = self;
self.detailView.delegate = self;
self.detailView.multipleTouchEnabled=YES;
[self.view addSubview:self.detailView];
[super viewDidLoad];
self.title = NSLocalizedString(@"Routes", nil);
self.detailArray = [[NSMutableArray alloc] init];
NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=Chennai&destination=Madurai&sensor=false"];
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];
NSError* error;
NSMutableDictionary* parsedJson = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSArray *allkeys = [parsedJson allKeys];
for(int i = 0; i < allkeys.count; i++){
if([[allkeys objectAtIndex:i] isEqualToString:@"routes"]){
NSArray *arr = [parsedJson objectForKey:@"routes"];
NSDictionary *dic = [arr objectAtIndex:0];
NSArray *legs = [dic objectForKey:@"legs"];
for(int i = 0; i < legs.count; i++){
NSArray *stepsArr = [[legs objectAtIndex:i] objectForKey:@"steps"];
for (int i = 0; i < stepsArr.count; i++) {
NSLog(@"HTML INSTRUCTION %@", [[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"]);
NSLog(@"############################");
[self.detailArray addObject:[[stepsArr objectAtIndex:i] objectForKey:@"html_instructions"] ];
}
}
}
}
});
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
return [self.detailArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 5.0f, 300.0f, 30.0f)];
label.text=[NSString stringWithFormat:@"%@",[self.detailArray objectAtIndex:indexPath.row]];
label.numberOfLines = 3;
label.font = [UIFont fontWithName:@"Helvetica" size:(12.0)];
label.lineBreakMode = UILineBreakModeWordWrap;
label.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:label];
[label release];
return cell;
}
테이블 뷰에 detailArray를 표시하려고합니다. 그러나 테이블 뷰에 null 값을 표시합니다. NSlog에는 현재 값이 표시됩니다. direction 값이 설정된 detailArray입니다. TableView.if에 표시 할 수있는 모든 것이 가능합니다. displayArray의 상수 값을 TableView에 올바르게 표시합니다. 아무도 알지 못하면 도와주세요. 나는 당신의 귀중한 답변을 기다리고 있습니다. 고마워요.NSMutableArray 테이블 뷰의 Null 값 표시
detailArray에 값을 추가 한 직후에 중단 점을 추가하여 detailArray에 값이 있는지 확인하십시오. – Anila
왜 'cellForRowAtIndexPath :'에서 테이블 뷰에 위임자를 설정 했습니까? 왜 cellForRowAtIndexPath :'method ??에서 테이블 뷰를 다시 읽어 들일 것인가? 'cellForRowAtIndexPath : method'에서이 두 줄을 지우십시오. tableView.delegate = self; 및 [self.detailView reloadData]; –
값을 보정하는 아닐라 세부 배열. –