自定义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)]; ...
随机推荐
- [BS] 小知识点总结-02
1. dispatch_GCD 可让某操作延迟x秒执行 //模拟网速慢,延迟3s返回数据(就会导致右侧数据和左侧标签不对应) dispatch_after(dispatch_time(DISPATC ...
- 商业智能BI和ERP的融合之路
企业在发展过程中为了更好的跟上同行业的步伐,甚至是为了在众多企业中脱颖而出,他们会主动寻求全面的企业解决方案.但是由于行业的快速发展,需求的不断增长,市面上的智能软件层出不穷,这也给了企业选择的困难. ...
- gcc选项-g与-rdynamic的异同_转
转自:http://www.tuicool.com/articles/EvIzUn gcc 的 -g ,应该没有人不知道它是一个调试选项,因此在一般需要进行程序调试的场景下,我们都会加上该选项,并且根 ...
- [MVCSharp]MVC# Overview概述
MVC# Overview概述 Abstract: This article gives an overview of MVC# - a Model-View-Presenter framework ...
- DLL项目报错:fatal error lnk1104: cannot open file "...\xxx.dll"
在生成DLL的时候报这个错, 生成不了DLL 检查生成DLL的路径是否有其他程序在使用... 或者把杀毒软件关了试试...
- 重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部
1.监听按钮点击 2.判断是否是点击的同一个按钮(记录上次点击的按钮) 3.当重复点击相同按钮时,需要获取当前按钮对应控制器刷新界面 3.1 判断是否重复点击按钮,代码写在哪里? ...
- paml正选择处理时序列里有终止密码子怎么处理掉
先用氨基酸序列进行比对,然后追溯回核苷酸序列,根据氨基酸序列的gap进行密码子去gap,这样不会出现终止子,能最大可能的保留其生物学意义
- java中HashSet详解(转)
HashSet 的实现 对于 HashSet 而言,它是基于 HashMap 实现的,HashSet 底层采用 HashMap 来保存所有元素,因此 HashSet 的实现比较简单,查看 HashSe ...
- ADO.net 防止SQL 字符串注入攻击
规避SQL注入 如果不规避,在黑窗口里面输入内容时利用拼接语句可以对数据进行攻击 如:输入Code值 p001' union select * from Info where '1'='1 //这样可 ...
- SQL 面向对象(委托)
委托:也称为代理,事件也是一种委托:定义在类的最外面 1.定义委托关键字:delegate函数签名:签名和函数保持一致定义委托的时候要根据函数来定义public delegate int First( ...