iOS UITableView的一些方法
项目中用到的一些tabview 问题及对应方法:
一.tableview
1.下划线左对齐
//步骤一:(加在 viewdidload方法中)
if([tabView respondsToSelector:@selector(setSeparatorInset:)])
{
[tabView setSeparatorInset:UIEdgeInsetsZero];
}
if
([tabView respondsToSelector:@selector(setLayoutMargins:)])
{
[tabView setLayoutMargins:UIEdgeInsetsZero];
}
//步骤二:修改分割线方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
{
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
二.cell
1.自定义cell获取选中的cell
NSIndexPath *indexPath = [tabView indexPathForSelectedRow];
UITableViewCell *cell = [tabView cellForRowAtIndexPath:indexPath];
cell.myLable.text= @"abc";
2.下拉列表单选(文字选中变色等)
//选中变色
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"选中某项变色");
SortTableViewCell *cell = [tabView cellForRowAtIndexPath:indexPath];
cell.sortLable.textColor = RGBCOLOR(, , );
} //再次点击取消
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"取消某项变色");
SortTableViewCell *cell = [tabView cellForRowAtIndexPath:indexPath];
cell.sortLable.textColor = [UIColor blackColor];
}
补充:如果还要默认选中第一项同时还得触发触发didselect方法 用以下方法
NSIndexPath *firstPath = [NSIndexPath indexPathForRow: inSection:];
[tabView selectRowAtIndexPath:firstPath animated:YES scrollPosition:UITableViewScrollPositionTop];
if ([tabView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
[tabView.delegate tableView:tabView didSelectRowAtIndexPath:firstPath];
}
3. cell的单选和多选
项目需要做试题的单选和课程下载的多选,首先想到用tabview的didselect配合didDeselect两个协议的方法(参考:http://www.2cto.com/kf/201412/364359.html),后来没用;
因为试题ABCD四个选项的单选题样式 所以在cell中加上button按钮解决;而下载是有分区的多选样式就根据下载图片的前后位置不同分别采取了cell加button的方法和系统自带的编辑方法
4.取消多余空白cell
tabView.tableFooterView = [[UIView alloc] init];//去掉空白cell
5.点击效果
(1).自定义点击时的背景色
UIView *view = [[UIView alloc]init];
view.backgroundColor = RGBCOLOR(, , );
cell.selectedBackgroundView = view;
(2).点击后返回cell的颜色为无色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
(3).点击时有颜色变化 返回cell的颜色为无色(配合自定义cell选中背景色)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
三.混合嵌套
1.tableview二级菜单
iOS UITableView的一些方法的更多相关文章
- IOS UITableView的代理方法详解
一.UITableViewDataSourc(数据源代理) 1.必须实现的回调方法 返回每个分区的行数 - (NSInteger)tableView:(UITableView *)tableView ...
- iOS UITableView的分割线短15像素,移动到最左边的方法(iOS8)
有好几个朋友问我ios 分割线端了一些 如何解决,于是我就写一篇博客吧.为什么我说是少了15像素呢?首先我们拖拽一个默认的tableview 控件! 看下xcode5 面板的inspector(检查器 ...
- iOS开发UITableView基本使用方法总结
本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...
- iOS开发UITableView基本使用方法总结 分类: ios技术 2015-04-03 17:51 68人阅读 评论(0) 收藏
本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...
- iOS开发UITableView基本使用方法总结1
UITableView基本使用方法 1.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDataSource 2.然后 ...
- iOS-提高iOS开发效率的方法和工具
提高iOS开发效率的方法和工具 介绍 这篇文章主要是介绍一下我在iOS开发中使用到的一些可以提升开发效率的方法和工具. IDE 首先要说的肯定是IDE了,说到IDE,Xcode不能跑,当然你也可能同时 ...
- IOS UITableView NSIndexPath属性讲解
IOS UITableView NSIndexPath属性讲解 查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...
- iOS UISearchController 的使用方法
iOS UISearchController 的使用方法 UISearchController 让用户在 UISearchBar 上输入搜索关键词,展示搜索结果或者进行其他操作.UISearchCon ...
- iOS UITableView划动删除的实现
标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...
随机推荐
- Java中的多线程操作初探
问题引出: 说是java,其实还是在做android的时候遇到的问题,在android 4.0以后,访问网络必须在新线程中实现,所以才会遇到这个问题.只是为了方面说明问题,才新建一个java项目.在m ...
- 关于完成端口IOCP异步接收连接函数AcceptEx注意事项
AcceptEx方法有一个参数dwReceiveDataLength,指明了在收到连接后是否需要收到第一包数据才返回.需要注意的是,如果 dwReceiveDataLength=0,则当接收到一个连接 ...
- Mahout之Canopy Clustering深入理解
转自:http://www.cnblogs.com/vivounicorn/archive/2011/09/23/2186483.html Mahout学习——Canopy Clustering 聚类 ...
- js中的null和undefined
大部分编程语言一般有一个表示“无”的值,而js中却有两个,null和undefined.所以查了一些资料,小结在此,以便查阅. js中的变量有两大类,基本的值类型,引用类型.其中值类型分为:Undef ...
- (剑指Offer)面试题15:链表中倒数第k个结点
题目: 输入一个链表,输出该链表中倒数第k个结点. 例如:链表中有6个结点,从头到尾依次为1,2,3,4,5,6,则该链表的倒数第3个结点为4. 链表结点定义: struct ListNode{ in ...
- 32.怎样在Swift中实现TabBar和导航视图结合的项目?
导航栏和TabBar结合的项目,在我们平常开发中会经常看到,下面我们通过自定义的TabBar来实现一个导航和TabBar结合的Demo. 1.自定义TabBar import UIKit class ...
- <meta http-equiv = "X-UA-Compatible" cotent = "IE=edge,chrome=1"/>
<meta http-equiv = "X-UA-Compatible" cotent = "IE=edge,chrome=1"/> 制定ie调用哪 ...
- 对比两个同类型的泛型集合并返回差异泛型集合 ——两个List<类名>的比较
1: /// <summary> 2: /// 对比两个同类型的泛型集合并返回差异泛型集合 3: /// </summary> 4: /// <typeparam nam ...
- 【百度地图-安卓SDK】从头开始写android程序
[百度地图-安卓SDK]从头开始写android程序首先确保有这四个文件 安装jdk先安装android开发SDK(并不只是为eclipse服务的),即运行installer_r15-windo ...
- [Angular2 Router] Build Angular 2 Navigation with routerLink
Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...