如何隐藏UITableView中的一项
我最近工作中的一个iOS App中经常有在不同的场合,隐现菜单列表里某一项的需求.
如果初始化的时候就去掉某一项的话,有可能让序号变化, 处理上会比较麻烦容易出错.
我采用了初始化列表相同但是隐藏section的方式,保持序号不变,方便处理.
那么如何隐藏一个section呢?
其实很简单,就是将section的高度设置为0
重载 heightForRowAtIndexPath方法, 假设要隐藏section 1的话,
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == 1)
return 0;
else
return 60;
}
简单的列表这样就可以了.
如果你的菜单项带有header和footer, 也需要将他们隐藏, 同理重载heightForHeaderInSection 和 heightForFooterInSection 方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if(section == 1)
return 0.01;
else
return 18;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if(section == 1)
return 0.01;
else
return 16;
}
注意: 这里没有return 0, 而是return 0.01, 是因为这两个方法不接受0值, 返回0会不起作用. 因为是返回float类型, 所以返回一个较小的数,比如0.01之类的.
另外.如果你派生了viewForFooterInSection 或 viewForHeaderInSection, 隐藏的section要返回nil,否则隐藏不了, 这一点也很重要.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == 0) {
return footView0;
} else if (section == 1) {
return nil;
} else if (section == 2) {
return footView2;
} else if (section == 3) {
return footView3
} else if (section == 4)
return footView4;
return nil;
}
viewForHeaderInSection也是同理, 这样就可以隐藏一个section及其header和footer了
如何隐藏UITableView中的一项的更多相关文章
- iOS 中隐藏UITableView最后一条分隔线
如何优雅的隐藏UITableView中最后一条分割线? 这个问题是很常见,却又不太容易解决的. 可能通常的做法都是隐藏UITableView的分割线,自定义一条. 最近在使用弹出菜单的时候,同样遇到了 ...
- 【转】[教程]隐藏ActionBar中的MenuItem
原文网址:http://blog.csdn.net/appte/article/details/12104823 有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些 ...
- [教程]隐藏ActionBar中的MenuItem
有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些MenuItem,百度上找了很久没什好资料,还是Google了一下,StackOverFlow上有大神解决了. 先 ...
- [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 隐藏进程中的模块绕过IceSword的检测
标 题: [原创] 隐藏进程中的模块绕过IceSword的检测 作 者: xPLK 时 间: 2008-06-19,17:59:11 链 接: http://bbs.pediy.com/showthr ...
- sed tr 去除PATH中的重复项
最近发现由于自己不良的安装软件的习惯,shell的PATH路径包含了很多冗余的项.这里使用shell命令去除PATH的冗余项. export PATH=$(echo $PATH | sed 's/:/ ...
- ASP.NET Core 1.0 中的依赖项管理
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- [CareerCup] 2.1 Remove Duplicates from Unsorted List 移除无序链表中的重复项
2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this p ...
- 在xib里,拖一个UIView到UITableView中作为tableHeaderView
原贴地址:http://blog.csdn.net/haoxinqingb/article/details/41683881 内容 在xib里,拖一个UIView到UITableView中作为tabl ...
随机推荐
- 使用Word发表博客
使用浏览器编辑博客,会让你感到非常不方便,如果在没有网络的时候,就不能打开编辑器页面了,只能先写在word或其他编辑软件中.可以设置word使用word编辑并直接发布到博客. 文件 - 新 ...
- ASP.NET中Onclick和OnserverClick事件的区别
对于服务器按钮控件(即<asp:Button>类型的按钮): 服务器响应事件:OnClick 客户端响应属性:OnClientClick 对于html按钮控件(即<input typ ...
- Bash shell的内建命令:type
type指令是用来观察指令时来自于外部指令还是内建在bash中的指令. type [-tpa] name 选项与参数: :不加任何选项与参数时,type会显示出name是外部指令还是bash内建指 ...
- Java中main函数只能调用同类中的静态方法?
如果想调用本类中的非静态方法可以这么来写: public class TT{ public static void main(String[] args){ TT t = new TT(); t.fu ...
- Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...
- 《2---关于JDBC编程过程中驱动配置问题》
说明:我在Editplus中编写了一个简单的JDBC程序,用来测试是否和数据库连接正确.读者如有其它疑问,可以留言交流. [1]程序如下: import java.sql.*; public clas ...
- 一定要在主线程更新UI
在一些技术交流群里面,一些初学者(我表示我也是其中一人),总是会发现,为什么我UIView的animate方法,不会动!而是直接闪? 这是为什么呢? 一定要在主线程中更新UI! 一定要在主线程中更新U ...
- cocos2d-x 3.0 事件分发机制
在cocos2d-x 3.0中一共有五个事件监听器: 触摸事件(EventListenerTouch) 键盘响应事件 (EventListenerKeyboard) 加速器记录事件(EventList ...
- 推荐一个Android Studio很实用的插件android-butterknife-zelezny
当你按钮很多,你又懒得写代码,虽然通过重写onClick比较方便,那么我们能不能连这个switch都省略掉呢? 答案是肯定的,下面这个插件就帮我们解决了这个问题! Android-butterknif ...
- array_filter函数
利用array_filter函数轻松去掉多维空值,而数组的下标没有改变, 如果自定义过滤函数返回 true,则被操作的数组的当前值就会被包含在返回的结果数组中, 并将结果组成一个新的数组.如果原数组是 ...