0

カスタムテーブルビューセルを介して設計されているUITableビューがあります。セルごとにテキストを変えたいのでlabel、CustomCellにを追加して接続しましたIBOutletが、コードのロジック部分に頭を巻くのに非常に苦労しています。私はこれまでにこれを持っています:

//これは私のテーブルビューコントローラークラスにあります。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) {
        NSArray *object = [[NSBundle mainBundle]loadNibNamed:@"TableOfContentsCell" owner:self options:nil];
        
        for (id currentObject in object) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                
            cell = (TableOfContentsCell *)currentObject;
            break;
            }
        }
        
    }
    
    //cell.textLabel.textColor = [UIColor whiteColor];
    
    // Configure the cell...
    
    return cell;
}


//This is in my Custom Table View Cell Class.

-(void)setTableText{
cellLabel.text = [table.tableCellText objectAtIndex:0];
}

必要なテキストが配列内にあるときに、テキストを設定する方法がわかりません。

4

4 に答える 4

1

カスタムセルのラベルにデータをロードする理由がわかりません。明確にしてください。
次に、コメント構成セルの下で、セルをカスタマイズできます。textColor を設定するために行ったように。
TABLE VIEW CONTROLLER CLASSでその配列を宣言するだけです

次に、以下のコードを記述します。

    // Configure the cell...
    
    cell.cellLabel.text = [yourArrayName objectAtIndex:indexPath.row];
于 2012-08-14T05:44:21.597 に答える
0

tableView:cellForRowAtIndexPath から入力するだけです

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    // Configure the cell...
    cellLabel.text = [table.tableCellText objectAtIndex:indexPath.row];
    return cell;
}

テーブルビューがtable.tableCellTextにアクセスできることを確認してください。

于 2012-08-14T05:08:52.430 に答える
0

別のメソッドは必要ありません.qnのコードには、コメントされた2行があります...(//セルを構成します...)このコードをthtセクションに追加します

カスタム セルに 2 つのラベルがあり、それらにタグ (ここでは 1 と 2) を追加し、viewwithtag: メソッドによってコードでその参照を取得するとします。

UILabel *label=(UILabel *)[cell viewWithTag:1];
[label setText:@"2"];

UILabel *label2=(UILabel *)[cell viewWithTag:2];
[label2 setText:@"sasd"];

保持しなければならない条件は、セルの内容が一意にタグ付けされている必要があり、このメソッドを使用してカスタム セル内の任意のビューの参照を取得できることです。

于 2012-08-14T05:09:35.173 に答える
0

必要に応じてカスタム セル クラスを作成します。それから。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

 TableCustomCell *cell = (TableCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

//.....................

cell.yourLabel.text = [yourArray objectAtIndex:indexPath.row];

return cell;
}
于 2012-08-14T05:16:47.587 に答える