【问题标题】:update uitableview cell object更新 uitableview 单元格对象
【发布时间】:2010-12-27 09:16:35
【问题描述】:

我有一个 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;

}

【问题讨论】:

    标签: iphone uitableview uiwebview


    【解决方案1】:

    由于您使用的是“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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多