项目中用到的一些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. 在Ribbon中,中文换行位置不对怎么办

    在Ribbon代码的编写时,关于UI上面设置Button的中文字,经常会出现不想换行的地方换行的情况,比如下图: 我如果希望中国一行,然后只有一行怎么办呢. 网上流传的很多方法就是直接加空格,但是很遗 ...

  2. 清除SQL Management Studio记住的用户名和密码

    SQL Server Management Studio 2008 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\Micr ...

  3. iOS维码的生成和扫描

    iOS生成二维码(彩色 + 阴影) http://www.jianshu.com/p/85e131155b79?plg_nld=1&plg_uin=1&plg_auth=1&p ...

  4. Struts2 高危漏洞补丁版本为: Struts 2.3.15.1

    Struts2 昨天爆出高危漏洞,黑客利用这个漏洞可以执行任意命令(包括恶意的jsp代码),轻松绕过您的验证系统,登陆您的网站后台,使您的网站后台密码形同虚设!! 目前Struts2官方已经发布了一个 ...

  5. Objective-C 学习记录--toches、Motion/Size/Rect/Point/CGFloat/protocol

    - (void)touchesBegan touchesEnd touchesCancelled touchesMoved //代表的是手指在屏幕上的动作,开始 结束 取消 移动 //还有就是代表摇动 ...

  6. 线程池:ThreadPoolExecutor

    [ThreadPoolExecutor的使用和思考]   public ThreadPoolExecutor(int corePoolSize,                             ...

  7. JS:公历、农历互转

    先申明这段代码不是我写的,纯粹只是觉的比较好用,所以记录下来以后继续使用,也同样分享给大家,大家有更好的可以推荐给我,谢谢! function CalConv(M, dateStr) { if (da ...

  8. Linq使用Group By经验总结

    1.计数 var q = from p in db.Products group p by p.CategoryID into g select new { g.Key, NumProducts = ...

  9. Android中GridView的实现实例

    实现效果: activity文件代码: package com.tmacsky; import android.app.Activity; import android.os.Bundle; impo ...

  10. apache2 添加perl支持

    官方文档,很详细了. https://httpd.apache.org/docs/2.0/howto/cgi.html#configuring   我修改了/etc/apache2/sites-ava ...