0

ストーリーボードではなくコードで作成された UITableView があります。このテーブルは、他のチャンピオンを選択することで更新できますが、そうすると、古いデータを含む別のテーブルが表示されます...更新するたびに nil に設定します...

誰かがアイデアを持っていますか??

テーブルを埋めるために、私はこのコードを使用します

listVideo = [listGroupes objectAtIndex:indexPath.row];
montageListView= [[UITableView alloc] initWithFrame:listFrame style:UITableViewStylePlain];
montageListView.delegate = self;
montageListView.dataSource = self;
montageListView.layer.cornerRadius = 10;
[listMontagesView addSubview:montageListView];

別のオプションを持つ新しいビューがありますが、このコードに戻ると:

montagesListView removeFromSuperview];
montagesListView = nil;

そして私は同じコードでそれを補充します

listVideo = [listGroupes objectAtIndex:indexPath.row];
montageListView= [[UITableView alloc] initWithFrame:listFrame style:UITableViewStylePlain];
montageListView.delegate = self;
montageListView.dataSource = self;
montageListView.layer.cornerRadius = 10;
[listMontagesView addSubview:montageListView];

良いテーブルがありますが、古いデータを含む別のテーブルがあります...コードに問題はありません:/

行のセルのコードは次のとおりですが、これは問題ではないと思います。

    static NSString *MyIdentifier = @"MyIdentifier";
NSString *text;
// Try to retrieve from the table view a now-unused cell with the given identifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

// If no cell is available, create a new one using the given identifier.
if (cell == nil) {
    // Use the default cell style.
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:MyIdentifier];
}

if (tableView == groupListView) {
    text = [listGroupesNames objectAtIndex:indexPath.row];
}else {

    text = [[listVideo objectAtIndex:indexPath.row]description];
    if ([[listVideo objectAtIndex:indexPath.row]note] == 1) {
        cell.imageView.image = [UIImage imageNamed:@"good.png"];
    }
    if ([[listVideo objectAtIndex:indexPath.row]note] == 2) {
        cell.imageView.image = [UIImage imageNamed:@"neutre.png"];
    }
    if ([[listVideo objectAtIndex:indexPath.row]note] == 3) {
        cell.imageView.image = [UIImage imageNamed:@"bad.png"];
    }
}

if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    cell.textLabel.font=[UIFont systemFontOfSize:18.0];
    text = [NSString stringWithFormat:@"           %@",text];
}else{
    cell.textLabel.font=[UIFont systemFontOfSize:12.0];
}
if (tableView == groupListView) {
    cell.imageView.image = [UIImage imageNamed:@"group.png"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if(tableView == montageListView){
    cell.imageView.image = [UIImage imageNamed:@"videos.png"];
}
cell.textLabel.text = text;
return cell;
4

2 に答える 2

0

あなたの質問は少しわかりにくいですが、これが私の見解です。

テーブル ビュー内のデータを更新したいようですね。その場合、新しい UITableView を作成する必要はありません。呼び出すだけreloadDataで、UITableView は新しいデータのデリゲートとデータソースを照会します。

新しい UITableView インスタンスを追加しても、データソース メソッドとデリゲート メソッドで同じデータを返す場合、古いデータが表示されるだけです。メソッドを必ず更新してください。

于 2012-06-22T15:10:00.733 に答える
0

コードがなければ、問題が何であるかを正確に伝えることは不可能ですが、テーブル ビューを毎回再作成する場合は[tableView removeFromSuperview]、nil に設定する前に確認する必要があります。

于 2012-06-22T14:45:39.330 に答える