2013-05-07 2 views
0

json 파일에 title, subtitleurl이 있습니다.iOS6 JSON 개체 정렬

title을 알파벳 순으로 정렬하지만 urltitle으로 정렬되지 않으며 이유를 모르겠습니다.

이 내가 무슨 짓을했는지입니다 :

내가있는 tableView의 첫 번째 항목을 누르면, 내가 총 diffrent title에서 url를 얻을 수있다 어떻게됩니까
NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil]; 
    NSArray *arrayOfItems = [allDataDictionary objectForKey:@"items"]; 

    for (NSDictionary *diction in arrayOfItems) { 
     NSString *titles = [diction objectForKey:@"title"]; 
     NSString *station = [diction objectForKey:@"url"]; 

     [jsonArray addObject:titles]; 
     [jsonStations addObject:station]; 

// SORT JSON 
     NSArray *sortedArray; 
     sortedArray = [jsonArray sortedArrayUsingComparator:^NSComparisonResult(NSString *title1, NSString *title2) 
         { 
          if ([title1 compare:title2] > 0) 
           return NSOrderedDescending; 
          else 
           return NSOrderedAscending; 
         }]; 
     [jsonArray setArray:sortedArray]; 

. tableView에서 urltitle과 일치하는 제목을 얻으려면 어떻게해야합니까? 여기있는 tableView의 :

는 어떤 도움을

편집

감사 didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    if(indexPath.row == _currentRadio) { 
     return; 
    } 

    if(_radio) { 
     [_radio shutdown]; 
     [_radio release]; 
     _radio = nil; 
    } 

    [_statusLabel setText:@""]; 
    [_titleLabel setText:@""]; 

    _currentRadio = indexPath.row; 
    NSString *radioUrl = [jsonStations objectAtIndex:indexPath.row]; 
    if([radioUrl hasPrefix:@"mms"]) { 
     _radio = [[MMSRadio alloc] initWithURL:[NSURL URLWithString:radioUrl]]; 
    } else { 
     _radio = [[HTTPRadio alloc] initWithURL:[NSURL URLWithString:radioUrl]]; 
    } 

    if(_radio) { 
     [_radio setDelegate:self]; 
     [_radio play]; 
    } 



    [self.tableview reloadData]; 
} 
+0

'tableView : didSelectRowAtIndexPath :'구현을 게시 할 수 있습니까? –

+0

원하는 테이블 뷰를 삽입했습니다. –

+0

이 문제를 이해할 수 있을지 모르겠지만 'jsonStations'을 정렬하지 않는 동안'jsonArray'를 정렬하기 때문에'jsonStations'에서 올바른 URL을 얻지 못하는 것 같습니다. 즉, 배열은 더 이상 같은 정렬 순서를 갖지 않습니다. 'arrayOfItems'를 테이블의 데이터 소스로 사용하는 것이 더 쉽지 않을까요? 정렬과 관련하여 동기화해야하는 두 개의 개별 배열을 갖는 것은 좋지 않습니다. 가능하지만 좋은 생각은 아닙니다. –

답변

0

코드는 코드에 대한 또 다른 설정을 잘못 배치 정렬 문제를 해결했다.