如果整个程序界面都只是使用UITableView来搭建,一般需要如下步骤:

(1)向界面上拖一个UITableView

(2)设置数据源

(3)设置代理

(4)遵守代理协议

 上述过程相对繁琐,为了简化操作,直接使用UITableViewController,但要一定要注意:需要和主控制器类进行关联,还有就是不要把UIViewController当成UITableViewController使用。
 
自定义TableViewCell(在ATDemoCell.m里):
+ (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的使用的更多相关文章

  1. iOS UITableView 与 UITableViewController

    很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...

  2. UITableViewController和XML解析还有地图的简单结合

    然后我的代码就按照上面的这个顺序输出. #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interfa ...

  3. UITableViewController和延时执行、自定义控件

    1.在UITableViewController中,self.view就是self.tableView, 两个对象的指针地址是一样的 2.自定义类继承UITableViewCell, 重写父类方法 / ...

  4. iOS--通讯录(UITableViewController)

    本文主要实现通讯录的部分功能(分组名.索引.分组的组名)等等功能: 废话不多说了,先上效果图: 在工程中需要导入一个plist文件,文件图如图: 工程目录文件如图: 工程程序如图所示: RootTab ...

  5. iOS--(UITableViewCell)、(UITableViewController)微信个人主页

    本文主要实现了微信的个人主页的设置: 目录文件如下: 实现代码如下: RootTableViewController.h #import <UIKit/UIKit.h> @interfac ...

  6. iOS UITableView , UITableViewController ,UITableViewCell实现全国各省市遍历,选择相应的地区

    我们先看一下效果                   代码如下 首先是第一个页面 rootTableViewController.h #import <UIKit/UIKit.h> #im ...

  7. iOS7上在xib中使用UITableViewController设置背景色bug

    今天用xcode5.1设置xib中,用静态的方式设置UITableViewController中的tableview,把tableview中的backgroundColor改变后,xib上有效果,但是 ...

  8. UITableView & UITableViewController

    内容概要: 本文先讲解了UITableView概述,然后主要从应用方面讲解了UITableViewController(包括add.delete.move单元cell的操作,以及UITableView ...

  9. iOS - UITableViewController

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableView : UIScrollView <NSCoding> @available(iOS ...

  10. UITableViewController 滚动引起的cocos2d动画暂停问题的解决

    UITableViewController 滚动引起的cocos2d动画暂停问题的解决 之前在使用UITableViewController进行滚动时,cocos2d的动画会暂停,直至滚动完毕才会继续 ...

随机推荐

  1. vue.js 创建组件 子父通信 父子通信 非父子通信

    1.创建组件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  2. Jrebel 工具学习

    Jrebel 可快速实现热部署,节省了大量重启时间,提高了个人开发效率.网上可搜索到破解版. http://baike.baidu.com/link?url=wuzv7Wa7SMUKltJr-dyta ...

  3. 【Python】Python time mktime()方法

    描述 Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数. 如果输入的值不 ...

  4. java 中 Stringbuff append源代码浅析

    public synchronized StringBuffer append(String str) {        super.append(str);        return this;  ...

  5. 2011 Multi-University Training Contest 7 - Host by ECNU

    AC: F I. rank 40/88. 开场看了F发现是个简单的DP,随便写了一下WA,,,发现把样例倒着输就过不了了...原来是忘了最后的时候开始上课的话可能上不了多久... 想到一个简洁的状态方 ...

  6. BZOJ 1834 网络扩容(最大流+费用流)

    对于第一问,直接求最大流. 对于第二问,建源点s和汇点t,s连1容量为INF,费用为0的边,n连t容量为最大流+k,费用为0的边.这样就把最大流限制为最多增加k了. 限制需要求扩充的最小费用,原图的边 ...

  7. html的body内标签之图片及表格

    <li> list 标签定义和用法: <li> 标签定义列表项目. <li> 标签可用在有序列表 (<ol>) 和无序列表 (<ul>) 中 ...

  8. 转:DP和HDP

    Dirichlet Process and Hierarchical Dirichlet Process 原文:http://hi.baidu.com/zentopus/item/46a622f5ef ...

  9. 【题解】CF#285 E-Positions in Permutations

    挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 nu ...

  10. bzoj1483: [HNOI2009]梦幻布丁(链表+启发式合并)

    题目大意:一个序列,两种操作. ①把其中的一种数修改成另一种数 ②询问有多少段不同的数如1 2 2 1为3段(1 / 2 2 / 1). 昨晚的BC的C题和这题很类似,于是现学现写居然过了十分开心. ...