iOS에서 json을 배우려고합니다. UITableView
을 사용하여 json 데이터를 구현하려고합니다. 제목 및 부제의 내 tableview 행에 값이 표시됩니다. 제목에 데이터를로드 할 수 있지만 부제로로드하려고하면 부제가 이고 결과는이며 json의 해당 필드에 많은 키 쌍 값이 주어지기 때문에 앱이 다운됩니다. 그래서 그것은 tableview에서 서브 제목으로 표시 할 수 없습니다.키 쌍의 키를 확인하는 방법을 사용할 수 있습니까?
내 질문은 어떻게 자막을로드 할 수 있으며 많은 키 쌍 값을 사용할 수있는 경우 해당 데이터를 표시하기 위해 다른 tableview로 리다이렉트됩니다.
내 코드 :
- (void)viewDidLoad {
[super viewDidLoad];
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://query.yahooapis.com/v1/public/yql?q=select+*+from+weather.forecast+where+woeid%3D1100661&format=json"]];
NSError *error=nil;
id response=[NSJSONSerialization JSONObjectWithData:data options:
NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:&error];
if (error) {
NSLog(@"%@",[error localizedDescription]);
} else {
_query = [response objectForKey:@"query"];
NSLog(@"%@",_query);
_keyArray = [_query allKeys];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_keyArray 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] ;
}
NSString *key = [_keyArray objectAtIndex:indexPath.row];
//NSString *dictionary = [_query objectForKey:key];
NSString *dictionary = [_query objectForKey:key];
cell.textLabel.text = key;
cell.detailTextLabel.text = dictionary;
return cell;
}
감사합니다.
에 따라 다름. cell.detailTextLabel에 무엇을 표시 하시겠습니까? –
저는 여기서 당신이 정말로 결과물로 얻고 자하는 것을 이해하기는 매우 어렵지만, 할 수는 없습니다. 이 결과로 정말로 원하는 것을 언급 한 이미지를 추가하십시오. –
자막 값이 새 사전 인 경우 하위 키 - 값 쌍을 표시하려면 테이블 뷰를 확장하거나 새 테이블 뷰로 푸시시겠습니까? –