更新 uitableview 单元格对象

发布于 2024-10-09 21:53:55 字数 682 浏览 0 评论 0原文

我有一个表视图,其第一行包含一个 uiwebview 。当用户单击按钮时,我想用新的对象更改此表的 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;

}

i have a tableview that contains a uiwebview in its first row. i would like to change this tables' webview object with new one when user clicks a button. i am using the code given below but it does not work fine. older object is there and the newer one is over it although i recreate the webview. how can i remove the older one from cell?

thanks...

- (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;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛滥成性 2024-10-16 21:53:55

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

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

以下是熟悉 UITableView 的教程:
http://developer.apple.com/库/ios/#documentation/userexperience/conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html

Since you are using "dequeueReusableCellWithIdentifier", your should reconfigure the cell each time when the cell is displayed.
Please remember that the cells with same identity will be reused. It's better to set the same identity to one particular type of cells, typically cells with same subviews and layout.

This is sample for how to load data and reconfigure a cell: http://code.google.com/p/tweetero/source/browse/trunk/Classes/MessageListController.m

Here is a tutorial to get familiar with UITableView:
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/CreateConfigureTableView/CreateConfigureTableView.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文