2011-10-10 15 views
0

thisのようにuitableviewを作成します。サーバーからデータをロードし、その値をRowの列に割り当てます。私はスタックのlinkを見たが、私にとっては役に立たなかった。 UPDATE 私のコード: -風景モードでGRIDのような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; 
} 

が、私は与えられた画像のように表示したいです。この問題を克服するために私を助けてください。前もって感謝します。

答えて

2

これはあなたが提示する方法よりも少しコードが必要になります。 あなたのフィールドごとに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 
    } 
} 

・ホープ、このことができます:あなたが別の色を管理できるように は、タグ内の行のインデックスを保管してください。

+0

私はあなたに投票して解決策を受け入れるでしょう。どうもありがとうございました。 – Lion

関連する問題