我可以显示/隐藏UITableView中的某个单元格,取决于另一个单元格的状态吗? [英] Can I show/hide a certain cell in an UITableView depending on the state of another cell?

查看:151
本文介绍了我可以显示/隐藏UITableView中的某个单元格,取决于另一个单元格的状态吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView样式分组,我用来设置我的应用程序中的一些选项。我想这个UITableView的单元格之一只显示取决于是否激活这个UITableView的另一个单元格。如果不是,第一个单元格应该显示(最好有一个平滑的动画),如果是,第一个单元格应该隐藏。



我试过返回 nil 在相应的 -tableView:cellForRowAtIndexPath:中隐藏单元格,但是不起作用而是抛出异常。 p>

我目前陷入困境,如何解决这个问题,所以我希望你能指出一个正确的方向。

p> http://iphonedevelopment.blogspot.com/ 2010/01 / navigation-based-core-data-application.html



他在NSFetchedResultsController上下文中使用这个,但你可以看到他如何使用各种调用添加/删除单元格&



现在,在你的情况下,你需要修改你使用的任何数组来托管用于生成tableView中的行的数据,当你激活您的单元格,然后有选择地使用:




  • tableView:insertRowsAtIndexPaths:withRowAnimation:

  • deleteRowsAtIndexPaths:withRowAnimation:

  • tableView:insertSections:withRowAnimation:

  • tableView:deleteSections:withRowAnimation:



来调整事情(你可以从tableView:reloadData :,开始,但是效率低下)。



我意识到API可能有点令人生畏,但花时间阅读它,并理解各种呼叫做什么。了解UITableView如何使用其数据源和委托,以及在选择/删除单元格时发生的事件链等,如果您想获得正确的(无崩溃),则非常重要。


I have a UITableView with style "Grouped" which I use to set some options in my App. I'd like for one of the cells of this UITableView to only show up depending on whether another of this UITableView's cells is activated or not. If it's not, the first cell should show up (preferably with a smooth animation), if it is, the first cell should hide.

I tried returning nil in the appropriate -tableView:cellForRowAtIndexPath: to hide the cell, but that doesn't work and instead throws an exception.

I'm currently stuck and out of ideas how to solve this, so I hope some of you can point me in the right direction.

解决方案

Here's a handy post in which the author provides some source code for performing animations on the currently selected cell:

http://iphonedevelopment.blogspot.com/2010/01/navigation-based-core-data-application.html

He's using this in a NSFetchedResultsController context, but you can see how he's using various calls to add/remove cells & sections.

Now, in your case, you'll need to modify whatever array you're using to host the data used to generate the rows in your tableView when you "activate" your cell, then selectively use:

  • tableView:insertRowsAtIndexPaths:withRowAnimation:
  • tableView:deleteRowsAtIndexPaths:withRowAnimation:
  • tableView:insertSections:withRowAnimation:
  • tableView:deleteSections:withRowAnimation:

to adjust things accordingly (you can start with tableView:reloadData:, but it's inefficient).

I realize that the API can be a bit daunting, but take the time to read through it and understand what the various calls do. Understanding how the UITableView uses its datasource and delegate, as well as the chain of events that occur when cells are selected/deleted/etc., is important if you want to get things just right (and crash-free).

这篇关于我可以显示/隐藏UITableView中的某个单元格,取决于另一个单元格的状态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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