-2

我正在处理来自这里的 json 数据,并且必须在 UITableView 中显示数据。

我必须按字母顺序显示部分的内容。每个部分包含多行,每行包含两个标签。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    int section = [indexPath section];

    int row = [indexPath row];

    UITableViewCell *cell =[[UITableViewCell alloc]init];


     UILabel *label1=[[UILabel alloc]initWithFrame:CGRectMake(10, 8, 30, 25)];
     label1.font=[UIFont boldSystemFontOfSize:20];
     label1.backgroundColor=[UIColor lightGrayColor];
     label1.TextAlignment=UITextAlignmentCenter;
     label1.textColor=[UIColor whiteColor];
     label1.text=[[[[[jsonObject valueForKey:@"leagues"]objectAtIndex:section]valueForKey:@"leagues"]objectAtIndex:row]valueForKey:@"id"];

    UILabel *label2=[[UILabel alloc]initWithFrame:CGRectMake(45, 8, 250, 25)];
    label2.font=[UIFont systemFontOfSize:18];
    label2.backgroundColor=[UIColor clearColor];
    label2.text=[[[[[jsonObject valueForKey:@"leagues"]objectAtIndex:section]valueForKey:@"leagues"]objectAtIndex:row]valueForKey:@"league"];


    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    [cell.contentView addSubview:label1];
    [cell.contentView addSubview:label2];
    return cell;
}

提前致谢和问候.....

4

1 回答 1

1

If you save your JSON encoded object into objects such as NSMutableArray. Then all you need to is simply implement some method...say

- (void)sortMyData {}

which implements some known algorithm, such as MergeSort, QuickSort or BubbleSort. Then before you set your table, you call this method to sort your data and you're good.

NOTE:

It is very common to "bend" the code on the server side -> sort it before you send it.

于 2012-10-15T08:26:35.567 回答