更新uitableview单元格对象

时间:2010-12-27 09:16:35

标签: iphone uitableview uiwebview

我有一个tableview,其第一行包含一个uiwebview。当用户单击按钮时,我想用新的表更改此表的webview对象。我使用下面给出的代码,但它不能正常工作。虽然我重新创建了webview,但旧的对象在那里,而新的对象已经在它上面了。我怎样才能从细胞中移除旧的?

感谢...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSLog(@"NİL.......");
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
} else {
    NSLog(@"NOT NİL.......");
}

[cell addSubview:webView];  


return cell;

}

1 个答案:

答案 0 :(得分:0)

由于您使用的是“dequeueReusableCellWithIdentifier”,因此每次显示单元格时都应重新配置单元格。
请记住,具有相同身份的单元格将被重用。最好将相同的标识设置为一种特定类型的单元格,通常是具有相同子视图和布局的单元格。

这是有关如何加载数据和重新配置单元格的示例:http://code.google.com/p/tweetero/source/browse/trunk/Classes/MessageListController.m

这是一个熟悉UITableView的教程: http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html