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的动画会暂停,直至滚动完毕才会继续 ...
随机推荐
- 自测之Lesson12:信号量
题目:创建一个包含5个信号量的信号集. 完成代码: #include <stdio.h> #include <sys/ipc.h> #include <sys/sem.h ...
- c++ string需要注意的地方
There are multiple answers based on what you are doing with the string. 1) Using the string as an id ...
- UVALive - 6864 Strange Antennas 扫描线
题目链接: http://acm.hust.edu.cn/vjudge/problem/87213 Strange Antennas Time Limit: 3000MS 题意 一个雷达能够辐射到的范 ...
- 在用js拼接html时,给元素加不上事件的问题
问题描述:有时,发起ajax请求成功后,需要用js去拼接一小段html字符串,然后给某些元素添加事件时,事件总是加不上. 解决办法:在success 回调函数内,给元素添加事件绑定. 代码如下: $. ...
- ubuntu中下载sublime相关问题
1.SublimeText3的安装 在网上搜索了一些ubuntu下关于sublime-text-3安装的方法,在这里针对自己尝试的情况进行反馈: 方法一(未成功): 在终端输入以下代码: sudo a ...
- js移动端滑块验证解锁组件
本文修改自PC端的js滑块验证组件,PC端使用的是onmousedown,onmouseup,nomousemove.原文找不到了,也是博客园文章,在此感谢广大网友的生产力吧. 说下对插件和组件的理解 ...
- monaco editor 实现自定义提示(sql为例)
monaco editor :https://www.cnblogs.com/XHappyness/p/9414177.html 这里实现自己定义的提示: .vue <template> ...
- 错误 10 非静态的字段、方法或属性“Test10.Program.a”要求对象引用
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test ...
- 第60天:js常用访问CSS属性的方法
一. js 常用访问CSS 属性的方法 我们访问得到css 属性,比较常用的有两种: 1. 利用点语法 box.style.width box.style.top 点语法可以得到 ...
- 【bzoj2259】[Oibh]新型计算机 堆优化Dijkstra
题目描述 Tim正在摆弄着他设计的“计算机”,他认为这台计算机原理很独特,因此利用它可以解决许多难题. 但是,有一个难题他却解决不了,是这台计算机的输入问题.新型计算机的输入也很独特,假设输入序列中有 ...