-2

NSArrayの友達リストがviewdidloadあり、各セルが で構成されるカスタマイズされたテーブル ビューを持っています。テーブル ビュー セルにLable配列要素を表示したいと考えてLableいます。

私のコードとして

tableList1 = [[NSArray 

alloc]initWithObjects:@"Harendra",@"Satyendra",@"Jitendra",@"Sandeep",@"Dick",@"nihyan",@"alex

",@"Gorav",nil];

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];


    }


//         ********   LableView    *******


UILabel* cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(200,12, 141, 111)];
cellLabel.textColor=[UIColor greenColor];
cellLabel.font=[UIFont boldSystemFontOfSize:18];
//cell.textLabel.text = [callDetailArray objectAtIndex:indexPath.row];
cell.textLabel.text =[tableList1 objectAtIndex:indexPath.row];
//  cellLabel.text =[NSArray arrayWithArray:tableList];
cellLabel.text = @"Lorem Ipsum";
cellLabel.backgroundColor = [UIColor clearColor];
cellLabel.opaque = NO;

[cell.contentView addSubview:cellLabel];



 NSLog(@" arr count in Friends list   %i",tableList1.count);
4

2 に答える 2

-1

tableList1なるように変更instance variable

cell.textLabel.text =[self.tableList1 objectAtIndex:indexPath.row];

また

cell.textLabel.text =[_tableList1 objectAtIndex:indexPath.row];
于 2013-08-31T09:24:35.543 に答える
-1

このコードを使用

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

//********   LableView    *******

UILabel* cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,12, 141, 111)];
cellLabel.textColor=[UIColor greenColor];
cellLabel.font=[UIFont boldSystemFontOfSize:18];
cellLabel.text = [tableList1 objectAtIndex:indexPath.row];
cellLabel.backgroundColor = [UIColor clearColor];
cellLabel.opaque = NO;

[cell.contentView addSubview:cellLabel];

または、コードに追加したこの 2 つのメソッドを確認してください。

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

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

このコードがお役に立てば幸いです。

于 2013-08-31T09:29:31.753 に答える