2012-06-22 64 views
0

我有一个UITableView不是在故事板中创建的,而是由代码创建的。这张桌子可以通过选择一些其他的冠军刷新,但是当我这样做时,有另一张桌子与旧数据...我设置为零时间我刷新...重新启动UITableView问题

有人有一个想法?

为了填补我使用此代码表

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; 

回答

0

没有代码是不可能的确切地告诉问题是什么,但是如果您每次都重新创建表格视图,那么在将其设置为零之前,您需要确保先执行[tableView removeFromSuperview]

+0

是的,我这样做,所以我从超级查看中删除它,然后我重新启动它,所以有新的表正确填写,但它后面有旧的...它没有得到触摸事件,但它在那里.. –

+0

Imma上传代码 –

0

你的问题有点难以理解,但这是我的承诺。

看来你想刷新表视图内的数据?如果是这样,你不需要创建一个新的UITableView。只需调用reloadData,UITableView将查询它是新数据的委托和数据源。

如果您添加一个新的UITableView实例,但在数据源和委托方法中返回相同的数据,它将只显示旧数据。确保你更新了方法。

+0

我有重新加载数据,它是一样的,是否有第二个表与旧数据,我不能发布图像,所以你看到的问题,钯:我对不起,我的英语XD –

+0

你更新委托和数据源方法来返回新的数据? – Rengers

+0

是的,我做了,但得到了同样的结果比重新创建列表... –