自定义tableViewCell
http://my.oschina.net/joanfen/blog/137601
效果如下图:可触发按钮事件

1、创建一个Empty Application

2、新建一个TableViewController,命名为MyTable

2.1在AppDelegate.h中添加@class 和property
|
1
2
3
4
5
6
7
8
9
10
11
12
|
#import <UIKit/UIKit.h>@class MyTable;@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;//声明@property (strong, nonatomic) MyTable *MyTableView;@end |
2.2在AppDelegate.m的 didFinishLaunchingWithOptions方法中
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; _MyTableView = [[MyTable alloc] initWithNibName:@"MyTable" bundle:nil]; //创建一个navigationController,也可不创建,直接将window的rootViewController设定为MyTableView,此处创建是为了让程序有NavigationController的属性,方便Push视图 UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:self.MyTableView]; self.window.rootViewController = nv; [self.window makeKeyAndVisible]; return YES;} |
2.3、在MyTable的viewWillAppear方法中
|
1
2
3
4
5
|
-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.title = @"自定义Table";} |
3、新建一个UITableViewCell类,命名为MyCell

4、新建一个View,命名与上面的相同(也可不同,只是命名相同更加方便)

4.1、将此View中的View删除,拖一个TableViewCell进来,将此tableViewCell的Custom Class改成3中新建的类MyCell

4.2.1、在cell中添加一个Label,创建映射

4.2.2、在Cell中添加一个TextField,创建映射

4.3.3、在Cell中添加一个Switch,创建映射

4.3.4、在Cell中添加一个segment,创建映射

5、在MyTable.m中,补充tableViewDataSource方法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ // Return the number of sections. return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // Return the number of rows in the section. return 4;} |
补充CellForRow方法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"MyCell"; //自定义cell MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell ==nil) { //加载MyCell.xib文件,此处loadNibNamed后面的参数CellIdentifier必须与MyCell.xib文件名相同,否则会无法加载,报错崩溃 NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; cell = (MyCell *)[nibArray objectAtIndex:0]; } cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; NSArray *array = [NSArray arrayWithObjects:@"姓名",@"性别",@"学历",@"保险", nil]; cell.title.text = [array objectAtIndex:indexPath.row]; //根据行数来确定每行内容 if (indexPath.row == 0||indexPath.row==2) { cell.textField.hidden = NO; cell.swich.hidden = YES; cell.segment.hidden = YES; } else if(indexPath.row == 1){ cell.textField.hidden = YES; cell.segment.hidden = NO; cell.swich.hidden = YES; } else if(indexPath.row == 3) { cell.textField.hidden = YES; cell.swich.hidden = NO; cell.segment.hidden = YES; } //设置TextField代理 cell.textField.delegate = self; return cell;}
|
自定义tableViewCell的更多相关文章
- 自定义 TableViewCell 的分割线
刚开始自定义 tableViewCell 的时候,用的是直接在 cell 上加一张 imageView 的方法,如果在点击 cell 的时候有页面的跳转,这样做没什么问题,但是,如果在点击 cell ...
- IOS开发自定义tableviewcell的注意点😄
自定义tableviewcell 1.xib,nib拖控件:awakefromnib: 设置2,不拖控件:- (instancetype)initWithStyle:(UITableViewCellS ...
- 自定义TableViewCell 的方式实现自定义TableView(带源码)
转载于:http://www.cnblogs.com/macroxu-1982/archive/2012/08/30/2664121.html 实现的效果 实现过程 Step One 创建 自定义Ta ...
- TableView,自定义TableViewCell
自定义Table 原理: http://blog.jobbole.com/67272/ http://www.cnblogs.com/wangxiaofeinin/p/3532831.html 补充: ...
- 在自定义TableViewCell类里面添加按钮事件触发不了的一些实践
我的自定义cell上面有5个控件,分别是一个背景的UIImageView,一个专辑的UIImageView(上面加了一个播放的button),一个专辑名字的UIImageView(上面加了显示标题的U ...
- [iOS基础控件 - 6.6] 展示团购数据 自定义TableViewCell
A.需求 1.头部广告 2.自定义cell:含有图片.名称.购买数量.价格 3.使用xib设计自定义cell,自定义cell继承自UITableViewCell 4.尾部“加载更多按钮”,以及其被点击 ...
- OC开发_代码片段——使用Xib自定义tableViewCell
一.实现步骤 1.新建一个XIB文件:描述cell——tableCell.xib 2.新建UITableViewCell的子类,也就是cell文件:封装XIB内部的所有东西——TestCell.m \ ...
- iOS开发:自定义tableViewCell处理的问题
还在适配iOS6,索性下一个版本不适配了~~~~~ 问题: *** Assertion failure in -[ PCDiaryDetailReplyCell layoutSublayersOfLa ...
- 自定义tableviewCell的分割线
第一种:addsubview UIView *line = [[UIView alloc]initWithFrame:CGRectMake(10, cellH-0.5, DEVW-10, 0.5)]; ...
随机推荐
- PetaPoco模糊查询
like '@0' 是错的,应该换成这样 like @0,原因是petapoco会自动把代码解析成'你好' 标签: Sql command = new Sql();command.Append(&q ...
- 单臂路由+DHCP+VLAN
使用思科模拟软件Cisco Packet Tracer Student,软件功能有限,只能架设简单的网络架构,适合初学者使用.
- javascript实例学习之八——无缝切换效果
无缝切换在网站的很多地方都有涉及,比如轮播图等. 基本思路: 1)将可视窗当前的元素复制,依次添加为ul中的子元素 2)改变ul整体的left取值(负的窗口值),动画缓动至想要的位置 3)将原视窗(已 ...
- iOS - (两个APP之间的跳转)
一个程序若要跳到另一个程序.需要在目标程序的plist文件里面修改: 打开info.plist,添加一项URL types 展开URL types,再展开Item0,将Item0下的URL ident ...
- maven 建立ssh项目
一.新建maven项目,配置ssh框架pom的最低支持 1.新建一个maven项目 依赖于org.springframework/spring-beans/4.1.5.RELEASE 的jar包 Gr ...
- 使用visual studio 2012 编译opencv2.4.9
最近,由于需要从opencv源码部分对opencv中的某个函数进行修改,以提升算法的速度,因此一直在尝试使用vs2012来编译opencv.期间不乏多次的失败.今天通过实验发现了自己编译的opencv ...
- ACdream 1157 Segments(CDQ分治)
题目链接:http://acdream.info/problem?pid=1157 Problem Description 由3钟类型操作:1)D L R(1 <= L <= R < ...
- HDU 2366 Space(二分计数)
Problem Description During a programming contest, teams cannot sit close to each other, because then ...
- 夺命雷公狗---node.js---9实现页面的跳转
废话不多说,我们先来看看项目的文件结构,如下所示: 然后我们创建一个index.js的文件让他来做端口监听,代码如下所示: var http = require('http'); var fs = r ...
- 安装VirtalBox虚拟机的一些问题归纳
1.分别下载VirtalBox软件和镜像,进行安装出现一个问题:换了一个.dll动态库,用管理员权限运行修改BIOS 中Intel Virtual Technology Enabled!2.功能:虚拟 ...