1.storyboard创建tableview,拉进controller中建立链接
2.storyboard建立约束:在连接器上将dataSource delegate拉到controller view的小按钮上
在controller.h上继承UIViewController<UITableViewDataSource,UITableViewDelegarte>
3.在controller.m中添加方法:
numberOfRowsInSection(注意这里counts是否真的有值)
cellForRowAtIndewPat
4.添加tableViewCell:
(1)在storyboard的tableview上拉上tableViewCell,设置好样式
(2)建一个tableviewcell的类,把样式的控件链接上.h
(3)storyboard上Custom Class改变指向类,Identifier上命名识别名称
5.在代码中指向cell:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIden = @"deviceListCell"; DeviceListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIden forIndexPath:indexPath]; cell.deviceName.text = @"test";//for test return cell; }
6.调整cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 80; }
二.纯代码自定义cell
参考:http://blog.csdn.net/u012350430/article/details/51181728
重写-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier:
//cell自定义用的是-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier方法 -(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) { //这里顺便介绍小UIButton的创建 //设置button的类型是UIButtonTypeRoundedRect UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置button的frame button.frame = CGRectMake(20, 20, 50, 50); //button正常状态title设置为Yes,被选择状态title设置为No [button setTitle:@"Yes" forState:UIControlStateNormal]; [button setTitle:@"No" forState:UIControlStateSelected]; //设置button响应点击事件的方法是buttonPressed: [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; //添加到cell [self addSubview:button]; //创建imageView添加到cell中 UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Totoro副本"]]; imageView.frame = CGRectMake(150, 20, 150, 100); [self addSubview:imageView]; } return self; } //buttonPressed:方法 -(void)buttonPressed:(UIButton *)button { //实现按钮状态的切换 button.selected = !button.selected; }
相关推荐
location驱动ios12.4 ios12.3 ios12.2 ios12.1 ios12.0 ios11.0 ios11.4
ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧版抓包工具ios旧...
iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16真机包iOS 16...
iOS 10 App Development Essentials: Learn to Develop iOS 10 Apps with Xcode 8 and Swift 3 Author: Neil Smyth Length: 816 pages Edition: 1 Language: English Publisher: CreateSpace Independent Publishing...
iOS 10 in Swift 3 非常好的ios书! 非常好的ios书! 非常好的ios书! 非常好的ios书! 非常好的ios书! 非常好的ios书!
iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS 15.4真机包iOS ...
HBuilderX申请iOS证书在线打包iOS文档,介绍iOS证书的申请及打包过程!
ios 录屏开发 支持 ios9 ios10 ios11
iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS11.1调试包iOS...
IOS布局控件使用自定义UITableViewCell 欢迎界面后台获取功能等项目设计IOS源码合集: ios三级展开列表TQMultistageTableView_10802 ios个性化每个tableMHNibTableViewCell ios分页的滚动视图 IOS可扩展底部TablBar ...
ios helper用于苹果ios系统的实用工具
xcode支持iOS15.2和iOS15.4
斯坦福ios7公开课纸牌源码(stanford ios7)
C语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 IOS.HC语言头文件 ...
C语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言头文件 IOSC语言...
【IOS苹果免签分发】苹果IOS绿标免签封装app隐藏顶部网址ios14不显示顶部网址跳转设置.zip
iOS代码混淆,马甲包混淆,iOS4.3被拒,ZFJObsLibV1.5.4-iOS混淆工具.dmg https://zfj1128.blog.csdn.net/article/details/95482006
一部2018最新的iOS学习教程,手把手教你如何使用xcode10
iOS9.3.2,iOS10 SDK 让你你的xocde5、6支持调试iOS9,iOS10。 源自Xcode_8_beta6,2016-08-24