-4

DataArray変更をデバッグしましたが、UITableViewから取得した新しいデータはまだ表示されませんDataArray。これは私のコードです:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];

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

        UILabel *FileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)];
        FileNameLabel.backgroundColor = [UIColor clearColor];
        FileNameLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
        FileNameLabel.font = [UIFont boldSystemFontOfSize:16];
        FileNameLabel.textColor = [UIColor blackColor];
         NSLog(@"File Temp 4 array: %@", temp);
        FileNameLabel.text =[temp objectAtIndex:indexPath.row];
        [cell.contentView addSubview: FileNameLabel];
        [FileNameLabel release];

    }
        return cell;
}

そしてupdate()機能ViewWillAppear

-(void) update
{
      if([FileCompletedArray count] != [temp count])
      {
            temp = [FileCompletedArray mutableCopy];
            NSLog(@"File Temp 1 array: %@", temp);
            [_tableView reloadData];
            NSLog(@"File Temp 2 array: %@", temp);
       }
}

解決策はありますか?

4

3 に答える 3

1

FileNameLabel.text =[temp objectAtIndex:indexPath.row];セル テキスト ( ) を設定するコードは、新しいセル インスタンスを作成するときにのみ実行されるため、これはセルの再利用の問題です。

新しいセルを作成するときに必要な設定と、セルを再利用または表示する準備をするときに必要な設定を区別する必要があります。

于 2013-07-04T11:34:03.783 に答える
1

reloadData を呼び出した後、cellForRowAtIndexPath が再度呼び出されますが、セルは既に作成されているため、テーブルビューはセルを再利用するため、ここでの適切な方法は、セル内のラベルを取得し、if(cell == nil)ブロック外のテキストを更新することです。私はあなたのコードを修正し、更新したものを以下に示します。

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

    UILabel *FileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)];
    FileNameLabel.tag = 1000;
    FileNameLabel.backgroundColor = [UIColor clearColor];
    FileNameLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
    FileNameLabel.font = [UIFont boldSystemFontOfSize:16];
    FileNameLabel.textColor = [UIColor blackColor];
     NSLog(@"File Temp 4 array: %@", temp);
    [cell.contentView addSubview: FileNameLabel];
    [FileNameLabel release];

}


UILabel *fileNameLbl = (UILabel*)[cell.contentView viewWithTag:1000];
fileNameLbl.text =[temp objectAtIndex:indexPath.row];

これで問題が解決するかどうかを確認してください。

于 2013-07-04T11:37:53.953 に答える