0

在我的 json 文件中,我有一个title,subtitleurl.

我对 进行排序title以按字母顺序设置项目,但url没有用 排序,title我不知道为什么。

这就是我所做的:

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 中的第一项,我会url从一个 total diffrent中得到title。我应该怎么做才能使标题与tableView中的urland相匹配?title

任何帮助表示赞赏

编辑:这是 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];
}
4

1 回答 1

0

代码放置错误,代码的另一个设置,修复了排序问题。

于 2013-05-23T06:06:36.577 回答