项目中用到的一些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的一些方法的更多相关文章

  1. IOS UITableView的代理方法详解

    一.UITableViewDataSourc(数据源代理) 1.必须实现的回调方法 返回每个分区的行数 - (NSInteger)tableView:(UITableView *)tableView ...

  2. iOS UITableView的分割线短15像素,移动到最左边的方法(iOS8)

    有好几个朋友问我ios 分割线端了一些 如何解决,于是我就写一篇博客吧.为什么我说是少了15像素呢?首先我们拖拽一个默认的tableview 控件! 看下xcode5 面板的inspector(检查器 ...

  3. iOS开发UITableView基本使用方法总结

    本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...

  4. iOS开发UITableView基本使用方法总结 分类: ios技术 2015-04-03 17:51 68人阅读 评论(0) 收藏

    本文为大家呈现了iOS开发中UITableView基本使用方法总结.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDa ...

  5. iOS开发UITableView基本使用方法总结1

    UITableView基本使用方法 1.首先,Controller需要实现两个delegate ,分别是UITableViewDelegate 和UITableViewDataSource 2.然后 ...

  6. iOS-提高iOS开发效率的方法和工具

    提高iOS开发效率的方法和工具 介绍 这篇文章主要是介绍一下我在iOS开发中使用到的一些可以提升开发效率的方法和工具. IDE 首先要说的肯定是IDE了,说到IDE,Xcode不能跑,当然你也可能同时 ...

  7. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

  8. iOS UISearchController 的使用方法

    iOS UISearchController 的使用方法 UISearchController 让用户在 UISearchBar 上输入搜索关键词,展示搜索结果或者进行其他操作.UISearchCon ...

  9. iOS UITableView划动删除的实现

    标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...

随机推荐

  1. circle area

    circle area Github 链接:传送门 本次作业要求 Create a program that asks for the radius of a circle and prints th ...

  2. c++字符串机理

    在windows编程中,由于编码方式的不同和c与c++的不同而造成了许多复杂的有关字符串之间的转换 首先,windows编码方式有ANSCLL和UNICODE,前者是单字符的,后者是双字符的. 然后, ...

  3. Notes on Probabilistic Latent Semantic Analysis (PLSA)

    转自:http://www.hongliangjie.com/2010/01/04/notes-on-probabilistic-latent-semantic-analysis-plsa/ I hi ...

  4. maven 基础整理

    教程 依赖管理 IDE设置121 IntelliJ,Edit Configurations中添加maven,选中 Resolve Workspace artifacts能自动编译依赖模块 内置命令 m ...

  5. [读书笔记]SQL约束

    目的:通过在列级或表级设置约束,确保数据符合某种数据完整性规则 实现:数据库主动地检查维护数据的完整性 手段:约束,数据类型,触发器 --------------------------------- ...

  6. (剑指Offer)面试题30:最小的k个数

    题目: 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 思路: 1.排序 把输入的n个整数排序,然后取前k个数: 时间复杂度 ...

  7. C#对HTML转译需要注意的问题

    在做B/S程序时我们多少会用到一点HTML特殊符号转译. 如:“&”——>“&” , "<"——>"<" , " ...

  8. JavaWeb-10(会话技术之session&amp;JSP)

    JavaWeb-会话技术之session&JSP 会话管理之Session技术 一.Session 在WEB开发中,server能够为每一个用户浏览器创建一个会话对象(session对象),注 ...

  9. Study notes for Clustering and K-means

    1. Clustering Analysis Clustering is the process of grouping a set of (unlabeled) data objects into ...

  10. freemarker中的round、floor和ceiling数字的舍入处理

    freemarker中的round.floor和ceiling数字的舍入处理 1.简易说明 (1)round:四舍五入 (2)floor:向下取整 (3)ceiling:向上取整 2.举例说明 < ...