Viewcontroller.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> @property(nonatomic,retain)NSArray *textlist; //定义一个数组名为textlist @property(nonatomic,retain)NSArray *imagelist; //定义一个数组名为imagelist @property(nonatomic,retain)NSArray *detallist; //定义一个数组名为detallist @property(nonatomic,retain)NSArray *colorlist; //定义一个数组名为colorlist @property(nonatomic,retain)UITableView *myTableView; //定义一个UITableView名为myTableView @end
Viewcontroller.m // // ViewController.m // UItableViewCell // // Created by 李旗 on 15/11/5. // Copyright (c) 2015年李旗. All rights reserved. // #import "ViewController.h" #import "TableViewCell.h" @interfaceViewController () @end @implementation ViewController - (void)viewDidLoad { [superviewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSArray *text = [NSArrayarrayWithObjects:@"中国",@"美国",@"韩国",@"英国", nil ]; self.textlist = text;//创建元素为国家的数组text NSArray *image = [NSArrayarrayWithObjects:@"yuan.jpg",@"yuan.jpg",@"yuan.jpg",@"yuan.jpg", nil]; self.imagelist = image;//创建元素为图片的数组 NSArray *detal = [NSArrayarrayWithObjects:@"详细信息", @"详细信息",@"详细信息",@"详细信息",nil]; self.detallist = detal;//创建元素为详细信息的数组 NSArray *color = [NSArrayarrayWithObjects:@"黄色",@"黑色",@"黄色",@"白色", nil]; self.colorlist = color;//创建元素为颜色的数组 UITableView *tableView = [[UITableViewalloc]initWithFrame:self.view.framestyle:UITableViewStylePlain];//创建一个tableview 大小和view的大小一样 style是plain self.myTableView = tableView; tableView.dataSource = self; tableView.delegate = self;//实现代理 [self.viewaddSubview:self.myTableView];//加载myTableView }//ViewController 需要在View上建立一个tableview,需要实现代理 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.textlistcount]; //Section的行数 } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { staticNSString *CellWithIndentifier = @"Cell"; NSInteger row = indexPath.row; TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIndentifier];//cell的重用机制 if(cell == nil) { cell = [[TableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellWithIndentifier]; //UITableViewCellStyleSubtitle 的样式是有图片大标题和小标题 } //NSUInteger row = [indexPath row]; cell.lbText.text = [self.textlistobjectAtIndex:row] cell.lbDetail.text = [self.detallistobjectAtIndex:row]; cell.imageView.image = [UIImageimageNamed: [self.imagelistobjectAtIndex:row]]; cell.lbColor.text = [self.colorlistobjectAtIndex:row];//把蚊子和图片放到cell对应的位置 return cell; } - (void)didReceiveMemoryWarning { [superdidReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
Tableviewcell.h #import <UIKit/UIKit.h> @interface TableViewCell (自己起的名字): UITableViewCell @property(nonatomic,retain)UILabel *lbText; @property(nonatomic,retain)UILabel *lbDetail; @property(nonatomic,retain)UIImageView *lbImage; @property(nonatomic,retain)UILabel *lbColor; //建立label来放需要的文字 建立imageview来显示图片 @end Tableviewcell.m #import "TableViewCell.h" @implementation TableViewCell - (void)awakeFromNib { // Initialization code } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier]; if(self){ self.lbText = [[UILabelalloc]initWithFrame:CGRectMake(70, 30, 50, 50)]; //设置lbText的位置 [selfaddSubview:self.lbText];//加载lbText self.lbDetail = [[UILabelalloc]initWithFrame:CGRectMake(70, 50, 250, 50)]; [selfaddSubview:self.lbDetail];//加载lbDetail //设置lbDetail的位置 self.lbImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 45, 40,40)]; //设置lbImage的位置 [self addSubview:self.lbImage];//加载lbImage self.lbColor = [[UILabelalloc]initWithFrame:CGRectMake(300, 50, 100, 50)]; [selfaddSubview:self.lbColor];//加载lbColor //设置lbColor的位置 } returnself; }//用TableViewCell来控制label的位置 - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [supersetSelected:selected animated:animated]; // Configure the view for the selected state } @end
结果如图
相关推荐
第二部分:iOS编程基础:Hello World应用程序如何工作的? 第三部分:iOS 编程向导:创建一个简单的表视图(Table View)应用程序 第四部分:定制UITableView表视图单元格 第五部分:如何处理UITableView中的行选择 ...
在下边的小例子中,我们将先实现显示一列数据,然后在每行添加图像,之后再看看UITableViewCell的四种分别是什么样的。最后再进行其他操作,比如设置缩进、修改字体大小和行高等。
ios入门
Ios简单的备忘录app,刚入门ios开发在网上看到了一个UITableView的使用例子便把网上的demo完善了一下功能,具体功能有: 添加一行数据,删除一行,修改一行,数据保存(重新启动app后数据还在),删除提示框(确认,取消). ...
iOS4的入门书籍 1 The iOS Software Development Kit (SDK) 2 A C Refresher 3 Just Enough Objective-C: Part One 4 Just Enough Objective-C: Part Two 5 Deploying to an iPhone, Debugging, and Testing 6 ...
玩 2 Play2 是用于创建共享通用非 UI 核心的 iOS 和 Android 应用程序的模板。 将您的新 iOS 和 Android 应用程序...捆绑的入门 iOS 和 Android 应用程序是“拉动刷新”类型,可在 UITableView 和 ListView 中显示结
自动预热(预取) UITableView和UICollectionView的内容。 在iOS 10上已弃用。 该库类似于iOS 10中添加的UITableViewDataSourcePrefetching和UICollectionViewDataSourcePrefetching ,我建议改为使用它。 使用...
入门指南: 14-改进表单用户界面 15-Perfom Segue 16-项目模型 17-结果作为项目实例 18-为Segue做准备 19-视图控制器中的UITableView 20-UI表格视图控制器 21-视频集 22-演讲模型 23-建立讲座方法 24-用于图
在iOS开发中,开发”表单”界面,字段稍微多一点的一般都用UITableView来做,而XLForm就是这样一个框架,它是创建动态表格视图最牛逼的iOS库, 用它实现表单功能,非常简单,省心省力。但是很可惜,搜索了很多文章都...
在iOS开发中,开发”表单”界面,字段稍微多一点的一般都用UITableView来做,而XLForm就是这样一个框架,它是创建动态表格视图最牛逼的iOS库, 用它实现表单功能,非常简单,省心省力。但是很可惜,搜索了很多文章都...
要安装它,只需将以下行添加到您的Podfile中: pod 'DBEmptyState'入门对于UITableView: # import < DBEmptyState> 对于UICollectionView: # import 显示空状态DBEmptyState包含类别,这些类别在表视图或集合视图...
Swift入门 Swift简介 Swift闭包 iOS开发基础 1.基础简介 2.UI基础之UIView简介 3.UI基础之UIControl简介 4.UI基础之文本 5.UI基础之UIButton 6.UI基础之UIImageView 7.UI基础之对话框 8.UI基础之UIScrollView简介 9....
包括使用(多个)情节提要板就像夸张的XIB 无法使用Storyboard时在代码中创建视图控制器以枚举类型化方式使用静态UITableView单元格图片文字多种语言的自动AppStore屏幕截图添加自定义React性基本的暗模式支持入门...
入门 并使用我们的 第一次使用TableViewKit? 阅读下面的部分 概述 TableViewKit设计为: 轻松开发具有不同页眉,页脚和多种单元格类型的自定义部分 支持有状态的部分 加强可重用性和可测试性 最后但并非最不重要的...
移动端开发的基础是UI开发,而UI开发中最基本的技能便是对列表(UITableView,UICollectionView,ListView,GridView)的使用.因此能够熟练使用列表,基本上已算是入门. 2.需要技能 在安卓,iOS,WP,H5任何一个平台开发过列表...
要求iOS 8.0+ 弧Xcode 6+入门例子下面举例说明如何使用表视图设置简单数据源。 NSString *cellId = @" tableViewCell " ;// register cells[ self .tableView registerNib: [UINib nibWithNibName: ...
UICollectionView和UITableView的SwiftUI实现。 以下是一些有用的功能: 支持预加载和onAppear / onDisappear 。 支持单元格选择,并自动支持SwiftUI编辑模式。 支持细胞的自动调整大小。 支持新的...