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 ...
随机推荐
- UVa11997K Smallest Sums(优先队列)
K Smallest Sums You're given k arrays, each array has k integers. There are kk ways to pick exactly ...
- Android 显示/隐藏 应用图标
PackageManager packageManager = getPackageManager(); ComponentName componentName = new ComponentName ...
- Apache Kafka:下一代分布式消息系统
[http://www.infoq.com/cn/articles/apache-kafka/]分布式发布-订阅消息系统. Kafka是一种快速.可扩展的.设计内在就是分布式的,分区的和可复制的提交日 ...
- wchar_t 和 char 之间转换
vc++2005以后,Visual studio 编译器默认的字符集为Unicode.VC中很多字符处理默认为宽字符wchar_t,如CString的getBuffer(),而一些具体操作函数的输入却 ...
- 30.怎样在Swift中添加运行时属性?
和OC一样,Swift中也可以添加运行时属性.下面将提供一个完整的例子,演示如何给按钮点击事件添加运行时属性. 1.示例 import UIKit var s_GofButtonTouchDownKe ...
- 不间断图片滚动JS
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期 2014-05-07) MSClass是一款通用不间断滚动JS封装类,几乎支持目前所有流行风格的图片或文字滚动,横向/竖向/连续/间断 ...
- UVA1151
//感觉刘汝佳老师的思维真的太厉害了orz /*摘录书上的一段话: 只需一个小小的优化即可降低时间复杂度:先求一次原图(不购买任何套餐)的最小生 成树,得到n-1条边,然后每次枚举完套餐后只考虑套餐中 ...
- ExtJs非Iframe框架加载页面实现
在用Ext开发App应用时,一般的框架都是左边为菜单栏,中间为tab页方式的显示区域.而tab页面大多采用的嵌入一个iframe来显示内容.但是采用iframe方式有一个很大的弊端就是每次在加载一个新 ...
- 分布式文件系统FastDFS设计原理
原文地址: http://blog.chinaunix.net/uid-20196318-id-4058561.html FastDFS是一个开源的轻量级分布式文件系统,由跟踪服务器(tracker ...
- 直接运行PowerShell脚本
以管理员权限运行下面语句:ftype Microsoft.PowerShellScript.1="C:\WINDOWS\system32\windowspowershell\v1.0\pow ...