ios中自定义cell,自定义UITableViewCell
来源:互联网 发布:c高级编程 编辑:程序博客网 时间:2024/05/21 21:45
通过继承UITableViewCell来自定义cell
1、创建一个空的项目、命名:
2、创建一个UITableViewController 并且同时创建xib:
3、设置AppDelegate.m中window的根控制器为刚刚创建的TableViewController:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; TableViewController *tableViewController = [[[TableViewController alloc] init] autorelease]; //自动释放 //设置根控制器 self.window.rootViewController = tableViewController; [self.window makeKeyAndVisible]; return YES;}
4、创建自定义的UITableViewCell:
5、创建自定义cell的xib 拖放需要的控件
选择User Interface。创建空的xib。拖入Cell控件。
完成自定义的cell控件。
设置cell控件的Identfier。绑定Cell类并且将控件的输出口关联到TableViewCell.h文件中。
6、对TableViewController类编码,在委托方法中设置自定义的Cell:
#import "TableViewController.h"#import "TableViewCell.h"@interface TableViewController (){ NSMutableArray *tableData; //表格数据}@end@implementation TableViewController- (id)initWithStyle:(UITableViewStyle)style{ self = [super initWithStyle:style]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; //初始化表格数据 tableData = [[NSMutableArray alloc] init]; for (int i = 0; i< 10; i++) { [tableData addObject:[NSString stringWithFormat:@"MyCellDemon%i",i]]; } //设置row的高度为自定义cell的高度 self.tableView.rowHeight = 90; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; }#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{#warning Potentially incomplete method implementation. return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{#warning Incomplete method implementation. return [tableData count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //指定cellIdentifier为自定义的cell static NSString *CellIdentifier = @"TableViewCell"; //自定义cell类 TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { //通过xib的名称加载自定义的cell cell = [[[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil] lastObject]; } //添加测试数据 cell.titleLabel.text = [tableData objectAtIndex:indexPath.row]; cell.content.text = @"这是一些测试数据"; //测试图片 cell.iamge.image = [UIImage imageNamed:@"testImage.jpg"]; return cell;}#pragma mark - Table view delegate- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}@end
最终效果:
- ios中自定义cell,自定义UITableViewCell
- iOS UITableViewCell重用以及自定义Cell
- iOS编程------自定义UITableViewCell / cell自适应高度
- 自定义UITableViewCell重用cell
- IOS中Cell自定义
- ios中代码自定义uitableviewcell
- IOS 自定义UITableViewCell:Cell高度、分割线、间距等
- IOS 自定义 tableView cell(UITableViewCell height) 高度
- 自定义UITableViewCell(2) 多个自定义cell
- 自定义UITableViewCell中获取按钮所在Cell的indexPath
- UITableViewCell中自定义cell添加手势没有响应解决方案
- iOS 自定义UITableViewCell中button事件处理
- iOS开发:自定义UITableViewCell
- iOS开发:自定义UITableViewCell
- IOS自定义UITableViewCell
- IOS 自定义UITableViewCell
- IOS自定义UITableViewCell
- ios 自定义tableViewcell,UITableViewCell
- 动态添加s 文件的方法
- 好记心,不如烂笔头
- android-settings添加字体更换-前篇-setting简单一览
- android存储方式
- mvc项目中,解决用Url.Content方法引用jquery文件后智能提示失效的办法
- ios中自定义cell,自定义UITableViewCell
- s3c6410中断处理
- 交通灯管理系统和银行业务调度系统学习
- HTML5 LocalStorage本地存储和sessionStorage使用
- 《大话存储2:存储系统架构与底层原理极限剖析》电子书下载
- ZOJ 2725 SG函数 DP
- 相机标定(1)---初识相机标定 标定的含义,意义
- VMware vSphere 5.1 各种ISO文件大集合[文件数:135][47.6 GB][含激活KEY]
- CALayer1-简介