如何从StoryBoard中设计的UITableView中删除静态单元格 [英] How to remove a Static Cell from a UITableView designed in StoryBoard

查看:98
本文介绍了如何从StoryBoard中设计的UITableView中删除静态单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案可能非常简单,但我无法找到它..!

The solution is probably very simple, but I couldn't just find it .. !

使用storyboard(iOS 5),我有一个 tableViewController ,以及一个设计有5个部分的STATIC表视图,每个部分内都有不同的静态单元格。

Working with storyboard (iOS 5), I have a tableViewController, and a designed STATIC tableview with 5 sections, with differents static cell inside each section.

我的问题是:如何在 viewWillAppear 中以编程方式删除单元格?

My question is: How to delete a cell programatically in the viewWillAppear?

例如,我有一个为日期设计的单元格

For example, I have a cell designed for a date

IBOutlet UITableViewCell * cellForDate;

并且..如果没有日期,我想删除我的单元格。

And.. if there's not date, I want to remove my cell.

cellForDate.hidden = true; //Hide the cell, but leave a blank space

我试过 [tableView deleteRowsAtIndexPaths ...] 无法正常工作

有人知道吗?

推荐答案

UITableViewDelegate 的tableView:willDisplayCell :forRowAtIndexPath: 方法。这是你可以操纵细胞外观的最终方法。但是这不会删除单元格应该占用的空间,因此您可以尝试的另一件事是使用 的tableView:heightForRowAtIndexPath: 相同协议的方法。

Try to hide the cell before it is shown, in UITableViewDelegate's tableView:willDisplayCell:forRowAtIndexPath: method. That's the final method where you can manipulate the cell's appearance. This however won't remove the space the cell should take, so another thing you can try is to set cell row's height to 0 using the tableView:heightForRowAtIndexPath: method of the same protocol.

另一种最强大的方法是设计一种方法,用于确定是否需要该部分中的日期单元格,具体取决于结果,返回该部分中的正确行数,并返回考虑该情况的其他节行单元格。然后在viewWillAppear上重新加载tableView的数据。

Another method, which is most robust, is to devise a method for determining whether you need the date cell in the section and depending on the result, return the proper number of rows in the section, and return other section row cells taking the situation into account. And then reload tableView's data on viewWillAppear.

这篇关于如何从StoryBoard中设计的UITableView中删除静态单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆