如何隐藏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 ...
随机推荐
- 制造行业流程管理的“IPO”思维
流程管理是企业从流程角度出发,关注流程是否增值的一套管理体系.从认识流程.到建立流程.到管理流程.再到优化流程,企业管理人员要去除不增值和低价值的流程,减少员工犯错误的机会,建立一套卓越的流程体系. ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- math and date、ajax、画布
console.log(Math.PI);//圆周率 console.log(Math.sqrt(4));//平方根2 console.log(Math.abs(-2.3));//绝对值2.3 con ...
- Titanium studio介绍
1.Titanium Studio 概述 TitaniumStudio是Appcelerator公司开发的一款基于Eclipse的,使开发者利用Javascript来快速开发移动应用程序的跨平台的集成 ...
- Linux Shell脚本编程--Head/Tail命令详解
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾,看看下面的范例:## ( ...
- Jquery与CSS选择器参考手册
- Duilib开发环境搭建
1.到github上下载最新版本,https://github.com/duilib/duilib,也没有发现版本号,就如图所示吧 2.我只安装了VS2008,而github上的已经更新到VS2013 ...
- Mutex 和 Lock
#include <future> #include <mutex> #include <iostream> #include <string> #in ...
- 好文mark
用oracle的dblink连接mysql. http://f.dataguru.cn/thread-267150-1-1.html hadoop的机架感知: 本地化策略,以及备份都要知道哪个节点在哪 ...
- [解决方案] pythonchallenge level 6
查看页面代码,知道找zip www.pythonchallenge.com/pc/def/channel.zip,查看zip下的readme.txt知道从90052,跑一遍知道要收集zip的comme ...