UITableViewController的使用
如果整个程序界面都只是使用UITableView来搭建,一般需要如下步骤:
(1)向界面上拖一个UITableView
(2)设置数据源
(3)设置代理
(4)遵守代理协议
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"cellID";
ATDemoCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[ATDemoCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:ID];
}
return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// 在此处定义控件
}
return self;
}
在cellForRowAtIndexPath数据源里调用
ATDemoCell *cell = [ATDemoCell cellWithTableView:tableView];
分割线设置
//设置分割线
[tableView setSeparatorInset:UIEdgeInsetsMake(0, -67, 0, 0)];
//分割线颜色
self.tableView.separatorColor = [UIColor redColor]; //隐藏分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//隐藏多余分割线
self.tableView.tableFooterView = [[UIView alloc] init];
取消选中样式
//取消选中样式
cell.selectionStyle = UITableViewCellSeparatorStyleNone;
设置背景色
// 改变整个tableView的颜色
tableView.backgroundColor = [UIColor greenColor] // 设置选中的背景色
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundView.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = selectedBackgroundView; // 设置默认的背景色 1
cell.backgroundColor = [UIColor blueColor]; // 设置默认的背景色 2
UIView *backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = [UIColor greenColor];
cell.backgroundView = backgroundView;
右边指示器显示,比如箭头、打勾,也可以自定义图片等等
// 显示箭头
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// 自定义显示,如开关Switch
cell.accessoryView = [[UISwitch alloc] init];
设置tableview 不能滚动
self.tableView.scrollEnabled =NO;
UITableViewController的使用的更多相关文章
- iOS UITableView 与 UITableViewController
很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...
- UITableViewController和XML解析还有地图的简单结合
然后我的代码就按照上面的这个顺序输出. #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interfa ...
- UITableViewController和延时执行、自定义控件
1.在UITableViewController中,self.view就是self.tableView, 两个对象的指针地址是一样的 2.自定义类继承UITableViewCell, 重写父类方法 / ...
- iOS--通讯录(UITableViewController)
本文主要实现通讯录的部分功能(分组名.索引.分组的组名)等等功能: 废话不多说了,先上效果图: 在工程中需要导入一个plist文件,文件图如图: 工程目录文件如图: 工程程序如图所示: RootTab ...
- iOS--(UITableViewCell)、(UITableViewController)微信个人主页
本文主要实现了微信的个人主页的设置: 目录文件如下: 实现代码如下: RootTableViewController.h #import <UIKit/UIKit.h> @interfac ...
- iOS UITableView , UITableViewController ,UITableViewCell实现全国各省市遍历,选择相应的地区
我们先看一下效果 代码如下 首先是第一个页面 rootTableViewController.h #import <UIKit/UIKit.h> #im ...
- iOS7上在xib中使用UITableViewController设置背景色bug
今天用xcode5.1设置xib中,用静态的方式设置UITableViewController中的tableview,把tableview中的backgroundColor改变后,xib上有效果,但是 ...
- UITableView & UITableViewController
内容概要: 本文先讲解了UITableView概述,然后主要从应用方面讲解了UITableViewController(包括add.delete.move单元cell的操作,以及UITableView ...
- iOS - UITableViewController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableView : UIScrollView <NSCoding> @available(iOS ...
- UITableViewController 滚动引起的cocos2d动画暂停问题的解决
UITableViewController 滚动引起的cocos2d动画暂停问题的解决 之前在使用UITableViewController进行滚动时,cocos2d的动画会暂停,直至滚动完毕才会继续 ...
随机推荐
- NProgress.js加载进度插件的简单实用方法
NProgress.js 说明: NProgress是基于jquery的,且版本要 >1.8 下载地址: https://github.com/rstacruz/nprogress API: N ...
- Python学习之路4 - 文件操作&编码转换
文件操作 文件操作大概分三步: 把文件打开. 操作文件. 把文件关上. 打开文件 打开文件用open()函数,打开成功后返回一个资源,具体语法如下. open(要打开的文件,打开方式,打开文件的格式, ...
- 找bug——加分作业
bug1:while循环中的*des++ =*src++; 不能这么写吧... bug2:maxSize没有定义 暂时看到这么多
- SDUST OJ 时间类的加、减法赋值运算
Problem F: 时间类的加.减法赋值运算 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 3801 Solved: 2210[Submit][St ...
- java定时执行任务(一)
需求: 经常遇到这样的需求:要求每天执行一次任务,执行任务时间是凌晨3点 实现: 为了便于检测,我假设的是下一分钟执行任务,每10秒重复执行.(对应现实项目:每天3点执行任务.那么就是下一个3点执行任 ...
- Java中的线程的优先级
Java 中线程优先级简介: 1. Java 提供一个线程调度器来监控程序中启动后进入就绪状态的所有线程. 按照线程的优先级决定应该调度哪个线程来执行. 2. 线程的优先级用数字表示, 范围从 1 到 ...
- TCP 接收窗口自动调节
https://technet.microsoft.com/zh-cn/magazine/2007.01.cableguy.aspx 欢迎来到 TechNet 杂志“网络专家”的第一部分.TechNe ...
- VC学习笔记:对话框
VC学习笔记:对话框 SkySeraph NOV.11st 2009 HQU Email-zgzhaobo@gmail.com QQ-452728574 Latest Modified Date:O ...
- [计算机网络] DNS何时使用TCP协议,何时使用UDP协议
DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP栈也算是个另类.但很少有人知道DNS分别在什么情况下使用这两种协议. 先简单介绍下TCP与UDP. ...
- 【Python】PYTHON中STRIP()方法学习笔记
Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''x ...