如何在横向模式下创建类似UITableView的网格?

如何在横向模式下创建类似UITableView的网格?,uitableview,iphone-sdk-4.3,Uitableview,Iphone Sdk 4.3,我想创建像这样的uitableview图像。从服务器加载数据并将值分配给行的列。我看到了堆栈的名称,但对我没有帮助。 更新 我的密码:- #pragma mark UITableViewDelegate methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView number

我想创建像这样的
uitableview
图像。从服务器加载数据并将值分配给行的列。我看到了堆栈的名称,但对我没有帮助。 更新 我的密码:-

#pragma mark UITableViewDelegate methods

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger) section {
    return [modelArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleGray;      
    // Configure the cell...
    RankModel *model = [modelArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@    %@     %@     %@     %@     %@",  model.level, model.name, model.score, model.rightAnswersCount, model.currentRank, model.country];
    return cell;
}

但我想像给定的图像一样显示。所以请帮助我克服这个问题。提前感谢。

这将需要比您提供的方法多一点的代码。 我的建议是,您可以为每个字段创建一个UILabel,而不是使用单个NSString。不要使用cell.textLabel,而是在cell.contentView上添加内容,然后您可以管理每个标签的颜色、背景色和标签的大小。“网格”外观可以通过为contentView指定白色和为每个标签的背景指定绿色来呈现。例如,创建单元格后:

cell.contentView.backgroundColor = [UIColor clearColor];

UILabel* aLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0.0, 100, 44)];
aLabel.tag = indexPath.row;
aLabel.textAlignment = UITextAlignmentLeft;
aLabel.textColor = [UIColor whiteColor];
aLabel.text = @"Test";
aLabel.backgroundColor = [UIColor greenColor];
[cell.contentView addSubview:aLabel];
[aLabel release];
在201或更高的位置开始下一个标签,以留下白色垂直线的印象。 将行索引保留在标记中,以便可以在以下位置管理备用颜色:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell
                                                        *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 0 || indexPath.row%2 == 0) {
        // use light green, get access to the labels via [cell.contentView viewWithTag:indexPath.row]
    } else {
        // use dark green   
    }
}

希望这能有所帮助。

我会尝试投票给你并接受解决方案。非常感谢你。