UITableView 重新加载单元格看法

发布于 2024-10-28 12:48:46 字数 602 浏览 8 评论 0原文

如何重新加载整个表格视图?在 -tableView:cellForRowAtIndexPath: 中,我将在线数据与用户设备上的数据进行比较,如果不相同,则显示一个下载内容的按钮。连接到此按钮的操作后,我想刷新整个表格视图,以再次将在线内容与本地内容进行比较。

reloadData 实际上会更新值,但不会删除这些按钮。我想更改单元格的显示方式。

换句话说,我希望此条件(在 -tableView:cellForRowAtIndexPath: 中)起作用,但它不起作用:

    if (![[NSFileManager defaultManager] fileExistsAtPath:someDir isDirectory:nil]) {   
        UIButton *bt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        (...)
        [cell addSubview:bt];
    }

现在要更新表格,我必须弹出视图控制器并再次按下它。我想用导航栏上的按钮来完成此操作。

提前致谢。

How can I reload the whole tableview? In -tableView:cellForRowAtIndexPath: I'm comparing data online with data on user's device and if it's not the same then I am displaying a button to download content. After actions connected to this button I'd like to refresh the whole tableview to complare again the content online with local one.

reloadData does in fact update values but it doesn't remove these buttons. I'd like to change the way cells are displayed..

In other words I want this condition (in -tableView:cellForRowAtIndexPath:) to work and it doesnt:

    if (![[NSFileManager defaultManager] fileExistsAtPath:someDir isDirectory:nil]) {   
        UIButton *bt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        (...)
        [cell addSubview:bt];
    }

To update the table now I have to pop the viewcontroller and push it again. I'd like to do it with button on navBar.

Thanks in advance.

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

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

发布评论

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

评论(2

我早已燃尽 2024-11-04 12:48:47

这是因为您正在使用 dequeueReusableCellWithIdentifier 缓存单元格。检查文档。您应该缓存两种类型的单元格,带按钮和不带按钮。

That is because you are caching cells with dequeueReusableCellWithIdentifier. Check the docs. You should cache 2 types of cells, with and without the button.

断爱 2024-11-04 12:48:47
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: @"your-id"];
if (cell)
{
     //Check if it should contain a button. If it shouldn't remove it
}
else
     //Create a fresh new cell
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: @"your-id"];
if (cell)
{
     //Check if it should contain a button. If it shouldn't remove it
}
else
     //Create a fresh new cell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文