2014-12-15 3 views
-1

동시에 tableview에 키를 표시하는 방법은 무엇입니까? 여기에 값을 표시 할 수 있습니다. "A"키를 tableview에 표시하는 방법

하세요 @ ..

: 나는 cell.textLabel의 setText에 키를 표시 할. . .

여기 내 코드입니다 고마워요 고맙습니다. NSURLRequest * request = [NSURLRequest requestWithURL : [NSURL URLWithString : @ "https://reserve.cdn-apple.com/AU/en_AU/reserve/iPhone/availability.json"]];

NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 

    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; 

     _listarr = [[NSMutableArray alloc]init]; 

     id list = [dic objectForKey:self.strStore]; 
     if ([list isKindOfClass:[NSDictionary class]]) { 
      NSDictionary *dictionary = (NSDictionary *)list; 

      NSArray *keys = [list allKeys]; 
      for (NSString *key in keys) { 
       NSString *teamname = (NSString *)[dictionary objectForKey:key]; 
       NSLog(@"",key); 
       [_listarr addObject:[NSString stringWithFormat:@"%@", teamname]]; 
      } 


     } else { 
      // Do some error handling 
     } 

} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    //必须返回与数据容器一样的数量,否则会报数据越界错 
    return [_listarr count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"thisCell"; 
    UITableViewCell *cell; 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

    [cell.textLabel setText:@"A"]; 
    [cell.detailTextLabel setText:[_listarr objectAtIndex:indexPath.row]]; 

    return cell; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 1; 
} 



@end 
+1

있는 NSDictionary는 키와 값을 가지고있는 NSArray는 값이 – CSmith

답변

0

안녕하세요이 코드는 당신은 내가 생각하는 필요 무엇을 제공합니다 ..

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; 
NSArray *array = [dic allKeys]; 
NSArray *temparray = [dic objectsForKeys:array notFoundMarker:[NSNull null]]; 
0

사용 NSDictionary와의 allKeysForObject:는 객체와 일치하는 키를 검색합니다. 객체는 isEqual:과 비교되며 간단한 NSString과 일치해야합니다.

배열이 너무 큰 경우 속도가 느려질 수 있습니다.이 경우 색인을 생성 할 수있는 키 값을 사용하여 다른 배열을 만들 수 있습니다.

관련 문제