ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:16.88KB ,
资源ID:10548599      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10548599.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(iOS开发UI篇UITableview控件基本使用.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

iOS开发UI篇UITableview控件基本使用.docx

1、iOS开发UI篇UITableview控件基本使用iOS开发UI篇UITableview控件基本使用iOS开发UI篇UITableview控件基本使用 一、一个简单的英雄展示程序 NJHero.h文件代码(字典转模型) 复制代码 1 #import Foundation/Foundation.h 2 3 interface NJHero : NSObject 4 /* 5 * 头像 6 */ 7 property (nonatomic, copy) NSString *icon; 8 /*iOS开发UI篇UITableview控件基本使用一、一个简单的英雄展示程序NJHero.h文件代码(字典

2、转模型)复制代码1 #import 23 interface NJHero : NSObject4 /*5 * 头像6 */7 property (nonatomic, copy) NSString *icon;8 /*9 * 名称10 */11 property (nonatomic, copy) NSString *name;12 /*13 * 描述14 */15 property (nonatomic, copy) NSString *intro;1617 - (instancetype)initWithDict:(NSDictionary *)dict;18 + (instancety

3、pe)heroWithDict:(NSDictionary *)dict;19 end复制代码NJViewController.m文件代码复制代码1 #import NJViewController.h2 #import NJHero.h34 interface NJViewController ()5 /*6 * 保存所有的英雄数据7 */8 property (nonatomic, strong) NSArray *heros;9 property (weak, nonatomic) IBOutlet UITableView *tableView;1011 end1213 implemen

4、tation NJViewController1415 #pragma mark - 懒加载16 - (NSArray *)heros17 18 if (_heros = nil) 19 / 1.获得全路径20 NSString *fullPath = NSBundle mainBundle pathForResource:heros ofType:plist;21 / 2.更具全路径加载数据22 NSArray *dictArray = NSArray arrayWithContentsOfFile:fullPath;23 / 3.字典转模型24 NSMutableArray *models

5、 = NSMutableArray arrayWithCapacity:dictArray.count;25 for (NSDictionary *dict in dictArray) 26 NJHero *hero = NJHero heroWithDict:dict;27 models addObject:hero;28 29 / 4.赋值数据30 _heros = models copy;31 32 / 4.返回数据33 return _heros;34 3536 - (void)viewDidLoad37 38 super viewDidLoad;39 / 设置Cell的高度40 /

6、当每一行的cell高度一致的时候使用属性设置cell的高度41 self.tableView.rowHeight = 60;42 self.tableView.delegate = self;43 4445 #pragma mark - UITableViewDataSource46 / 返回多少组47 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView48 49 return 1;50 51 / 返回每一组有多少行52 - (NSInteger) tableView:(UITableView *)tableVie

7、w numberOfRowsInSection:(NSInteger)section53 54 return self.heros.count;55 56 / 返回哪一组的哪一行显示什么内容57 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath58 59 / 1.创建CELL60 UITableViewCell *cell = UITableViewCell alloc initWithStyle:UITableViewCellStyleS

8、ubtitle reuseIdentifier:nil;61 / 2.设置数据62 / 2.1取出对应行的模型63 NJHero *hero = self.herosindexPath.row;64 / 2.2赋值对应的数据65 cell.textLabel.text = hero.name;66 cell.detailTextLabel.text = hero.intro;67 cell.imageView.image = UIImage imageNamed:hero.icon;68 / 3.返回cell69 return cell;70 71 #pragma mark - UITable

9、ViewDelegate72 /*73 / 当每一行的cell的高度不一致的时候就使用代理方法设置cell的高度74 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath75 76 if (1 = indexPath.row) 77 return 180;78 79 return 44;80 81 */8283 #pragma mark - 控制状态栏是否显示84 /*85 * 返回YES代表隐藏状态栏, NO相反86 */87 - (BOOL)prefers

10、StatusBarHidden88 89 return YES;90 91 end复制代码实现效果:代码注意点:(1)在字典转模型的代码处用下面的代码,为可变数组分配dictArray.count个存储空间,可以提高程序的性能NSMutableArray *models = NSMutableArrayarrayWithCapacity:dictArray.count;(2)设置cell的高度有三种办法可以设置cell的高度1) 可以在初始加载方法中设置,self.tableView.rowHeight = 60;这适用于当每一行的cell高度一致的时候,使用属性设置cell的高度。2)在st

11、oryboard中设置,适用于高度一致3)当每一行的cell的高度不一致的时候就使用代理方法设置cell的高度- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath if (1 = indexPath.row) return 180; return 44;二、cell的一些属性代码示例:复制代码 1 #import NJViewController.h 2 #import NJHero.h 3 4 interface NJViewController () 5

12、/* 6 * 保存所有的英雄数据 7 */ 8 property (nonatomic, strong) NSArray *heros; 9 property (weak, nonatomic) IBOutlet UITableView *tableView;1011 end1213 implementation NJViewController1415 #pragma mark - 懒加载16 - (NSArray *)heros17 18 if (_heros = nil) 19 / 1.获得全路径20 NSString *fullPath = NSBundle mainBundle pa

13、thForResource:heros ofType:plist;21 / 2.更具全路径加载数据22 NSArray *dictArray = NSArray arrayWithContentsOfFile:fullPath;23 / 3.字典转模型24 NSMutableArray *models = NSMutableArray arrayWithCapacity:dictArray.count;25 for (NSDictionary *dict in dictArray) 26 NJHero *hero = NJHero heroWithDict:dict;27 models add

14、Object:hero;28 29 / 4.赋值数据30 _heros = models copy;31 32 / 4.返回数据33 return _heros;34 3536 - (void)viewDidLoad37 38 super viewDidLoad;39 / 设置Cell的高度40 / 当每一行的cell高度一致的时候使用属性设置cell的高度41 self.tableView.rowHeight = 60;42 self.tableView.delegate = self;4344 4546 #pragma mark - UITableViewDataSource47 / 返回

15、多少组48 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView49 50 return 1;51 52 / 返回每一组有多少行53 - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section54 55 return self.heros.count;56 57 / 返回哪一组的哪一行显示什么内容58 - (UITableViewCell *)tableView:(UITableView *)tab

16、leView cellForRowAtIndexPath:(NSIndexPath *)indexPath59 60 / 1.创建CELL61 UITableViewCell *cell = UITableViewCell alloc initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil;62 / 2.设置数据63 / 2.1取出对应行的模型64 NJHero *hero = self.herosindexPath.row;65 / 2.2赋值对应的数据66 cell.textLabel.text = hero.name;

17、67 cell.detailTextLabel.text = hero.intro;68 cell.imageView.image = UIImage imageNamed:hero.icon;69 70 / 2.3设置cell的辅助视图71 / cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;72 if (0 = indexPath.row) 73 cell.accessoryView = UIButton buttonWithType:UIButtonTypeContactAdd;74 else75 76 c

18、ell.accessoryView = UISwitch alloc init;77 78 / UIButton *btn = UIButton alloc init;79 / btn.backgroundColor = UIColor redColor;80 / cell.accessoryView = btn;81 82 83 / 2.4设置cell的背景颜色84 cell.backgroundColor = UIColor blueColor;85 86 / 设置默认状态的背景87 / UIView *view = UIView alloc init;88 / view.backgrou

19、ndColor = UIColor blueColor;89 / cell.backgroundView = view;90 91 UIImageView *iv = UIImageView alloc initWithImage:UIImage imageNamed:buttondelete;92 cell.backgroundView = iv;93 94 / 设置选中状态的背景95 UIView *view2 = UIView alloc init;96 view2.backgroundColor = UIColor purpleColor;97 cell.selectedBackgroundView = view2;98 / 3.返回cell99 return cell;100 101102103 #pragma mark - 控制状态栏是否显示104 /*105 * 返回YES代表隐藏状态栏, NO相反106 */107 - (BOOL)prefersStatusBarHidden108 109 return YES;110 111 end

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1