1

私は2つの配列を持っています

1)nameArray; 2)数値配列;

これらの配列には名前と番号が含まれています。これらの名前と番号を nib を使用せずにテーブルビューに表示したいと考えています。プログラムでカスタム セルを作成する方法

4

2 に答える 2

0

UITableViewCellのサブクラスである必要がある新しいファイルを作成します。ここでは、好きな場所に表示できる2つのラベルを作成できます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *theID = @"TableViewCell";
    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:theID];

return cell;
}  

ここで、CustomCellはUITableViewCellのサブクラスです

于 2012-08-01T06:12:26.190 に答える
0
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"CellIdentifier";
CustomCellName *cell = (CustomCellName *)[tableView dequeueReusableCellWithIdentifier:identifier];
if(!cell) {
cell = [[CustomCellName alloc] initWithStyle:UITableViewStyleDefault reusableIdentifier:identifier];
}
cell.textLabel.text = [nameArray objectAtIndex:indexPath.row];
cell.subtextLabel.text = [numberArray objectAtIndex:indexPath.row];
return cell;
}

上記のコードはテストされていません。私はこれを行うためのコンピューターを使用していません(iPhoneでこれをすべて入力するのではなく)が、コードに関して必要なものとほぼ同じであるはずです。

textLabel=カスタムセルクラスのラベルに設定したプロパティ名subtextLabel=カスタムセルクラスのラベルに設定したプロパティ名

お役に立てれば!

于 2012-08-01T06:27:13.717 に答える