配色: 字号:
iOS中使用UItableviewcell实现团购和微博界面的示例
2016-11-11 | 阅:  转:  |  分享 
  
iOS中使用UItableviewcell实现团购和微博界面的示例

这篇文章主要介绍了iOS中使用UItableviewcell实现团购和微博界面的示例,开发语言基于传统的Objective-C,需要的朋友可以参考下

使用xib自定义UItableviewcell实现一个简单的团购应用界面布局

一、项目文件结构和plist文件





二、实现效果





三、代码示例

1.没有使用配套的类,而是直接使用xib文件控件tag值操作

数据模型部分:

YYtg.h文件

复制代码代码如下:

////YYtg.h//01-团购数据显示(没有配套的类)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import#import"Global.h"

@interfaceYYtg:NSObject@property(nonatomic,copy)NSStringbuyCount;@property(nonatomic,copy)NSStringicon;@property(nonatomic,copy)NSStringprice;@property(nonatomic,copy)NSStringtitle;YYinitH(tg)@end

YYtg.m文件

复制代码代码如下:

////YYtg.m//01-团购数据显示(没有配套的类)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import"YYtg.h"

@implementationYYtgYYinitM(tg)@end

主控制器

YYViewController.m文件

复制代码代码如下:

////YYViewController.m//01-团购数据显示(没有配套的类)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import"YYViewController.h"#import"YYtg.h"

@interfaceYYViewController()@property(nonatomic,strong)NSArraytg;@property(strong,nonatomic)IBOutletUITableViewtableview;

@end



复制代码代码如下:

@implementationYYViewController

-(void)viewDidLoad{[superviewDidLoad];self.tableview.rowHeight=100;}

#pragmamark-懒加载-(NSArray)tg{if(_tg==nil){NSStringfullpath=[[NSBundlemainBundle]pathForResource:@"tgs.plist"ofType:nil];NSArraytemparray=[NSArrayarrayWithContentsOfFile:fullpath];NSMutableArrayarrayM=[NSMutableArrayarrayWithCapacity:temparray.count];for(NSDictionarydictintemparray){YYtgtg=[YYtgtgWithDict:dict];[arrayMaddObject:tg];}_tg=[arrayMmutableCopy];}return_tg;}

#pragmamark-数据显示-(NSInteger)numberOfSectionsInTableView:(UITableView)tableView{return1;}-(NSInteger)tableView:(UITableView)tableViewnumberOfRowsInSection:(NSInteger)section{returnself.tg.count;}-(UITableViewCell)tableView:(UITableView)tableViewcellForRowAtIndexPath:(NSIndexPath)indexPath{//读取xib中的数据//NSArrayarrayM=[[NSBundlemainBundle]loadNibNamed:@"tgcell"owner:niloptions:nil];//UITableViewCellcell=[arrayMfirstObject];staticNSStringidentifier=@"tg";UITableViewCellcell=[tableViewdequeueReusableCellWithIdentifier:identifier];if(cell==nil){//cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];cell=[[[NSBundlemainBundle]loadNibNamed:@"tgcell"owner:niloptions:nil]firstObject];}YYtgtg=self.tg[indexPath.row];//设置数据//使用tagUIImageViewimgv=(UIImageView)[cellviewWithTag:1];imgv.image=[UIImageimageNamed:tg.icon];UILabelbuyCount=(UILabel)[cellviewWithTag:4];buyCount.text=[NSStringstringWithFormat:@"已有%@人购买",tg.buyCount];UILabeltitle=(UILabel)[cellviewWithTag:2];title.text=tg.title;UILabelprice=(UILabel)[cellviewWithTag:3];price.text=[NSStringstringWithFormat:@"$%@",tg.price];//返回cellreturncell;}

//隐藏状态栏-(BOOL)prefersStatusBarHidden{returnYES;}@end

使用xib自定义的UItableviewcell



代码分析:

上面的代码通过使用xib文件中各个控件的tag值,完成对每个部分数据的赋值和刷新。但是,作为主控制器,它应该知道xib文件中各个控件的tag值,它知道的是不是太多了呢?

为了解决上面的问题,我们可以为自定义的cell设置一个配套的类,让这个类来操作这个xib,对外提供接口,至于内部的数据处理,外界不需要关心,也不用关心。

改造后的代码如下:

2.使用xib和对应的类完成自定义cell的数据展示

新建一个类,用来管理对应的xib文件

注意类的继承类,并把该类和xib文件进行关联



YYtgcell.h文件代码:

复制代码代码如下:

////YYtgcell.h//02-团购(使用xib和类完成数据展示)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import#import"YYtg.h"

@interfaceYYtgcell:UITableViewCell@property(nonatomic,strong)YYtgyytg;

@end

YYtgcell.m文件

复制代码代码如下:

////YYtgcell.m//02-团购(使用xib和类完成数据展示)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import"YYtgcell.h"//私有扩展@interfaceYYtgcell()@property(strong,nonatomic)IBOutletUIImageViewimg;@property(strong,nonatomic)IBOutletUILabeltitlelab;@property(strong,nonatomic)IBOutletUILabelpricelab;@property(strong,nonatomic)IBOutletUILabelbuycountlab;@end



复制代码代码如下:

@implementationYYtgcell

#pragmamark重写set方法,完成数据的赋值操作-(void)setYytg:(YYtg)yytg{_yytg=yytg;self.img.image=[UIImageimageNamed:yytg.icon];self.titlelab.text=yytg.title;self.pricelab.text=[NSStringstringWithFormat:@"$%@",yytg.price];self.buycountlab.text=[NSStringstringWithFormat:@"已有%@人购买",yytg.buyCount];}@end

主控制器

YYViewController.m文件

复制代码代码如下:

////YYViewController.m//02-团购(使用xib和类完成数据展示)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import"YYViewController.h"#import"YYtg.h"#import"YYtgcell.h"

@interfaceYYViewController()@property(strong,nonatomic)IBOutletUITableViewtableview;

@property(strong,nonatomic)NSArraytg;@end



复制代码代码如下:

@implementationYYViewController

-(void)viewDidLoad{[superviewDidLoad];self.tableview.rowHeight=80.f;}#pragmamark-懒加载-(NSArray)tg{if(_tg==nil){NSStringfullpath=[[NSBundlemainBundle]pathForResource:@"tgs.plist"ofType:nil];NSArraytemparray=[NSArrayarrayWithContentsOfFile:fullpath];NSMutableArrayarrayM=[NSMutableArrayarrayWithCapacity:temparray.count];for(NSDictionarydictintemparray){YYtgtg=[YYtgtgWithDict:dict];[arrayMaddObject:tg];}_tg=[arrayMmutableCopy];}return_tg;}

#pragmamark-xib创建cell数据处理#pragmamark多少组-(NSInteger)numberOfSectionsInTableView:(UITableView)tableView{return1;}#pragmamark多少行-(NSInteger)tableView:(UITableView)tableViewnumberOfRowsInSection:(NSInteger)section{returnself.tg.count;}#pragmamark设置每组每行-(UITableViewCell)tableView:(UITableView)tableViewcellForRowAtIndexPath:(NSIndexPath)indexPath{staticNSStringidentifier=@"tg";YYtgcellcell=[tableViewdequeueReusableCellWithIdentifier:identifier];if(cell==nil){//如何让创建的cell加个戳//对于加载的xib文件,可以到xib视图的属性选择器中进行设置cell=[[[NSBundlemainBundle]loadNibNamed:@"tgcell"owner:niloptions:nil]firstObject];NSLog(@"创建了一个cell");}//设置cell的数据//获取当前行的模型YYtgtg=self.tg[indexPath.row];cell.yytg=tg;returncell;}

-(BOOL)prefersStatusBarHidden{returnYES;}

@end

3.对上述代码进行进一步的优化和调整(MVC)

优化如下:

(1)把主控制器中创建cell的过程抽取到YYtgcell中完成,并对外提供一个接口。

YYtgcell.h文件(提供接口)

复制代码代码如下:

#import#import"YYtgModel.h"

@interfaceYYtgcell:UITableViewCell@property(nonatomic,strong)YYtgModelyytg;

//把加载数据(使用xib创建cell的内部细节进行封装)+(instancetype)tgcellWithTableView:(UITableView)tableView;@end

YYtgcell.m文件(把创建自定义cell的部分进行封装)

复制代码代码如下:

////YYtgcell.m//02-团购(使用xib和类完成数据展示)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import"YYtgcell.h"//私有扩展@interfaceYYtgcell()@property(strong,nonatomic)IBOutletUIImageViewimg;@property(strong,nonatomic)IBOutletUILabeltitlelab;@property(strong,nonatomic)IBOutletUILabelpricelab;@property(strong,nonatomic)IBOutletUILabelbuycountlab;@end



复制代码代码如下:

@implementationYYtgcell

#pragmamark重写set方法,完成数据的赋值操作-(void)setYytg:(YYtgModel)yytg{_yytg=yytg;self.img.image=[UIImageimageNamed:yytg.icon];self.titlelab.text=yytg.title;self.pricelab.text=[NSStringstringWithFormat:@"$%@",yytg.price];self.buycountlab.text=[NSStringstringWithFormat:@"已有%@人购买",yytg.buyCount];}

+(instancetype)tgcellWithTableView:(UITableView)tableView{staticNSStringidentifier=@"tg";YYtgcellcell=[tableViewdequeueReusableCellWithIdentifier:identifier];if(cell==nil){//如何让创建的cell加个戳//对于加载的xib文件,可以到xib视图的属性选择器中进行设置cell=[[[NSBundlemainBundle]loadNibNamed:@"tgcell"owner:niloptions:nil]firstObject];NSLog(@"创建了一个cell");}returncell;}

@end

主控器中的业务逻辑更加清晰,YYViewController.m文件代码如下

复制代码代码如下:

////YYViewController.m//02-团购(使用xib和类完成数据展示)////Createdbyappleon14-5-29.//Copyright(c)2014年itcase.Allrightsreserved.//

#import"YYViewController.h"#import"YYtgModel.h"#import"YYtgcell.h"

@interfaceYYViewController()@property(strong,nonatomic)IBOutletUITableViewtableview;

@property(strong,nonatomic)NSArraytg;@end



复制代码代码如下:

@implementationYYViewController

-(void)viewDidLoad{[superviewDidLoad];self.tableview.rowHeight=80.f;}#pragmamark-懒加载-(NSArray)tg{if(_tg==nil){NSStringfullpath=[[NSBundlemainBundle]pathForResource:@"tgs.plist"ofType:nil];NSArraytemparray=[NSArrayarrayWithContentsOfFile:fullpath];NSMutableArrayarrayM=[NSMutableArrayarrayWithCapacity:temparray.count];for(NSDictionarydictintemparray){YYtgModeltg=[YYtgModeltgWithDict:dict];[arrayMaddObject:tg];}_tg=[arrayMmutableCopy];}return_tg;}

#pragmamark-xib创建cell数据处理

#pragmamark多少组-(NSInteger)numberOfSectionsInTableView:(UITableView)tableView{return1;}

#pragmamark多少行-(NSInteger)tableView:(UITableView)tableViewnumberOfRowsInSection:(NSInteger)section{returnself.tg.count;}

#pragmamark设置每组每行-(UITableViewCell)tableView:(UITableView)tableViewcellForRowAtIndexPath:(NSIndexPath)indexPath{//1.创建cellYYtgcellcell=[YYtgcelltgcellWithTableView:tableView];//2.获取当前行的模型,设置cell的数据YYtgModeltg=self.tg[indexPath.row];cell.yytg=tg;//3.返回cellreturncell;}

#pragmamark-隐藏状态栏-(BOOL)prefersStatusBarHidden{returnYES;}

@end

四、推荐调整的项目文件结构



这是调整后的文件结构,完整的MVC架构。

注意:注意文件的命名规范。

提示技巧:批量改名,操作如下:



修改为想要的名称:



实现一个简单的微博界面布局

一、实现效果



二、使用纯代码自定义一个tableview的步骤

1.新建一个继承自UITableViewCell的类

2.重写initWithStyle:reuseIdentifier:方法

添加所有需要显示的子控件(不需要设置子控件的数据和frame,子控件要添加到contentView中)

进行子控件一次性的属性设置(有些属性只需要设置一次,比如字体\固定的图片)

3.提供2个模型

数据模型:存放文字数据\图片数据

frame模型:存放数据模型\所有子控件的frame\cell的高度

4.cell拥有一个frame模型(不要直接拥有数据模型)

5.重写frame模型属性的setter方法:在这个方法中设置子控件的显示数据和frame

6.frame模型数据的初始化已经采取懒加载的方式(每一个cell对应的frame模型数据只加载一次)

三、文件结构和实现代码

1.文件结构



2.实现代码:

NJWeibo.h文件

复制代码代码如下:

#import

@interfaceNJWeibo:NSObject@property(nonatomic,copy)NSStringtext;//内容@property(nonatomic,copy)NSStringicon;//头像@property(nonatomic,copy)NSStringname;//昵称@property(nonatomic,copy)NSStringpicture;//配图@property(nonatomic,assign)BOOLvip;

-(id)initWithDict:(NSDictionary)dict;+(id)weiboWithDict:(NSDictionary)dict;@end

NJWeibo.m文件

复制代码代码如下:

#import"NJWeibo.h"

@implementationNJWeibo

-(id)initWithDict:(NSDictionary)dict{if(self=[superinit]){[selfsetValuesForKeysWithDictionary:dict];}returnself;}

+(id)weiboWithDict:(NSDictionary)dict{return[[selfalloc]initWithDict:dict];}

@end

NJWeiboCell.h文件

复制代码代码如下:

#import@classNJWeiboFrame;

@interfaceNJWeiboCell:UITableViewCell/接收外界传入的模型///@property(nonatomic,strong)NJWeiboweibo;

@property(nonatomic,strong)NJWeiboFrameweiboFrame;

+(instancetype)cellWithTableView:(UITableView)tableView;@end

NJWeiboCell.m文件

复制代码代码如下:

#import"NJWeiboCell.h"#import"NJWeibo.h"#import"NJWeiboFrame.h"

#defineNJNameFont[UIFontsystemFontOfSize:15]#defineNJTextFont[UIFontsystemFontOfSize:16]

@interfaceNJWeiboCell(www.visa158.com)/头像/@property(nonatomic,weak)UIImageViewiconView;/vip/@property(nonatomic,weak)UIImageViewvipView;/配图/@property(nonatomic,weak)UIImageViewpictureView;/昵称/@property(nonatomic,weak)UILabelnameLabel;/正文/@property(nonatomic,weak)UILabelintroLabel;@end



复制代码代码如下:

@implementationNJWeiboCell

+(instancetype)cellWithTableView:(UITableView)tableView{//NSLog(@"cellForRowAtIndexPath");staticNSStringidentifier=@"status";//1.缓存中取NJWeiboCellcell=[tableViewdequeueReusableCellWithIdentifier:identifier];//2.创建if(cell==nil){cell=[[NJWeiboCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];}returncell;}

/构造方法(在初始化对象的时候会调用)一般在这个方法中添加需要显示的子控件/-(id)initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString)reuseIdentifier{self=[superinitWithStyle:stylereuseIdentifier:reuseIdentifier];if(self){//让自定义Cell和系统的cell一样,一创建出来就拥有一些子控件提供给我们使用//1.创建头像UIImageViewiconView=[[UIImageViewalloc]init];[self.contentViewaddSubview:iconView];self.iconView=iconView;//2.创建昵称UILabelnameLabel=[[UILabelalloc]init];nameLabel.font=NJNameFont;//nameLabel.backgroundColor=[UIColorredColor];[self.contentViewaddSubview:nameLabel];self.nameLabel=nameLabel;//3.创建vipUIImageViewvipView=[[UIImageViewalloc]init];vipView.image=[UIImageimageNamed:@"vip"];[self.contentViewaddSubview:vipView];self.vipView=vipView;//4.创建正文UILabelintroLabel=[[UILabelalloc]init];introLabel.font=NJTextFont;introLabel.numberOfLines=0;//introLabel.backgroundColor=[UIColorgreenColor];[self.contentViewaddSubview:introLabel];self.introLabel=introLabel;//5.创建配图UIImageViewpictureView=[[UIImageViewalloc]init];[self.contentViewaddSubview:pictureView];self.pictureView=pictureView;}returnself;}

-(void)setWeiboFrame:(NJWeiboFrame)weiboFrame{_weiboFrame=weiboFrame;//1.给子控件赋值数据[selfsettingData];//2.设置frame[selfsettingFrame];}

/设置子控件的数据/-(void)settingData{NJWeiboweibo=self.weiboFrame.weibo;//设置头像self.iconView.image=[UIImageimageNamed:weibo.icon];//设置昵称self.nameLabel.text=weibo.name;//设置vipif(weibo.vip){self.vipView.hidden=NO;self.nameLabel.textColor=[UIColorredColor];}else{self.vipView.hidden=YES;self.nameLabel.textColor=[UIColorblackColor];}//设置内容self.introLabel.text=weibo.text;//设置配图if(weibo.picture){//有配图self.pictureView.image=[UIImageimageNamed:weibo.picture];self.pictureView.hidden=NO;}else{self.pictureView.hidden=YES;}}/设置子控件的frame/-(void)settingFrame{

//设置头像的frameself.iconView.frame=self.weiboFrame.iconF;//设置昵称的frameself.nameLabel.frame=self.weiboFrame.nameF;//设置vip的frameself.vipView.frame=self.weiboFrame.vipF;//设置正文的frameself.introLabel.frame=self.weiboFrame.introF;//设置配图的frame

if(self.weiboFrame.weibo.picture){//有配图self.pictureView.frame=self.weiboFrame.pictrueF;}}

/计算文本的宽高@paramstr需要计算的文本@paramfont文本显示的字体@parammaxSize文本显示的范围@return文本占用的真实宽高/-(CGSize)sizeWithString:(NSString)strfont:(UIFont)fontmaxSize:(CGSize)maxSize{NSDictionarydict=@{NSFontAttributeName:font};//如果将来计算的文字的范围超出了指定的范围,返回的就是指定的范围//如果将来计算的文字的范围小于指定的范围,返回的就是真实的范围CGSizesize=[strboundingRectWithSize:maxSizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:dictcontext:nil].size;returnsize;}

@end

NJWeiboFrame.h文件

复制代码代码如下:

//专门用来保存每一行数据的frame,计算frame

#import@classNJWeibo;@interfaceNJWeiboFrame:NSObject/头像的frame/@property(nonatomic,assign)CGRecticonF;/昵称的frame/@property(nonatomic,assign)CGRectnameF;/vip的frame/@property(nonatomic,assign)CGRectvipF;/正文的frame/@property(nonatomic,assign)CGRectintroF;/配图的frame/@property(nonatomic,assign)CGRectpictrueF;/行高/@property(nonatomic,assign)CGFloatcellHeight;

/模型数据/@property(nonatomic,strong)NJWeiboweibo;@end

NJWeiboFrame.m文件

复制代码代码如下:

#import"NJWeiboFrame.h"#import"NJWeibo.h"#defineNJNameFont[UIFontsystemFontOfSize:15]#defineNJTextFont[UIFontsystemFontOfSize:16]

@implementationNJWeiboFrame

-(void)setWeibo:(NJWeibo)weibo{_weibo=weibo;//间隙CGFloatpadding=10;//设置头像的frameCGFloaticonViewX=padding;CGFloaticonViewY=padding;CGFloaticonViewW=30;CGFloaticonViewH=30;self.iconF=CGRectMake(iconViewX,iconViewY,iconViewW,iconViewH);//设置昵称的frame//昵称的x=头像最大的x+间隙CGFloatnameLabelX=CGRectGetMaxX(self.iconF)+padding;//计算文字的宽高CGSizenameSize=[selfsizeWithString:_weibo.namefont:NJNameFontmaxSize:CGSizeMake(MAXFLOAT,MAXFLOAT)];CGFloatnameLabelH=nameSize.height;CGFloatnameLabelW=nameSize.width;CGFloatnameLabelY=iconViewY+(iconViewH-nameLabelH)0.5;self.nameF=CGRectMake(nameLabelX,nameLabelY,nameLabelW,nameLabelH);//设置vip的frameCGFloatvipViewX=CGRectGetMaxX(self.nameF)+padding;CGFloatvipViewY=nameLabelY;CGFloatvipViewW=14;CGFloatvipViewH=14;self.vipF=CGRectMake(vipViewX,vipViewY,vipViewW,vipViewH);//设置正文的frameCGFloatintroLabelX=iconViewX;CGFloatintroLabelY=CGRectGetMaxY(self.iconF)+padding;CGSizetextSize=[selfsizeWithString:_weibo.textfont:NJTextFontmaxSize:CGSizeMake(300,MAXFLOAT)];CGFloatintroLabelW=textSize.width;CGFloatintroLabelH=textSize.height;self.introF=CGRectMake(introLabelX,introLabelY,introLabelW,introLabelH);//设置配图的frameCGFloatcellHeight=0;if(_weibo.picture){//有配图CGFloatpictureViewX=iconViewX;CGFloatpictureViewY=CGRectGetMaxY(self.introF)+padding;CGFloatpictureViewW=100;CGFloatpictureViewH=100;self.pictrueF=CGRectMake(pictureViewX,pictureViewY,pictureViewW,pictureViewH);//计算行高self.cellHeight=CGRectGetMaxY(self.pictrueF)+padding;}else{//没有配图情况下的行高self.cellHeight=CGRectGetMaxY(self.introF)+padding;}}

/计算文本的宽高@paramstr需要计算的文本@paramfont文本显示的字体@parammaxSize文本显示的范围@return文本占用的真实宽高/-(CGSize)sizeWithString:(NSString)strfont:(UIFont)fontmaxSize:(CGSize)maxSize{NSDictionarydict=@{NSFontAttributeName:font};//如果将来计算的文字的范围超出了指定的范围,返回的就是指定的范围//如果将来计算的文字的范围小于指定的范围,返回的就是真实的范围CGSizesize=[strboundingRectWithSize:maxSizeoptions:NSStringDrawingUsesLineFragmentOriginattributes:dictcontext:nil].size;returnsize;}@end

主控制器

NJViewController.m文件

复制代码代码如下:

#import"NJViewController.h"#import"NJWeibo.h"#import"NJWeiboCell.h"#import"NJWeiboFrame.h"

@interfaceNJViewController()@property(nonatomic,strong)NSArraystatusFrames;@end



复制代码代码如下:

@implementationNJViewController

#pragmamark-数据源方法

-(NSInteger)tableView:(UITableView)tableViewnumberOfRowsInSection:(NSInteger)section{returnself.statusFrames.count;}

-(UITableViewCell)tableView:(UITableView)tableViewcellForRowAtIndexPath:(NSIndexPath)indexPath{NJWeiboCellcell=[NJWeiboCellcellWithTableView:tableView];//3.设置数据cell.weiboFrame=self.www.hunanwang.netstatusFrames[indexPath.row];//4.返回returncell;}#pragmamark-懒加载-(NSArray)statusFrames{if(_statusFrames==nil){NSStringfullPath=[[NSBundlemainBundle]pathForResource:@"statuses.plist"ofType:nil];NSArraydictArray=[NSArrayarrayWithContentsOfFile:fullPath];NSMutableArraymodels=[NSMutableArrayarrayWithCapacity:dictArray.count];for(NSDictionarydictindictArray){//创建模型NJWeiboweibo=[NJWeiboweiboWithDict:dict];//根据模型数据创建frame模型NJWeiboFramewbF=[[NJWeiboFramealloc]init];wbF.weibo=weibo;[modelsaddObject:wbF];}self.statusFrames=[modelscopy];}return_statusFrames;}

#pragmamark-代理方法-(CGFloat)tableView:(UITableView)tableViewheightForRowAtIndexPath:(NSIndexPath)indexPath{//NSLog(@"heightForRowAtIndexPath");//取出对应航的frame模型NJWeiboFramewbF=self.statusFrames[indexPath.row];NSLog(@"height=%f",wbF.cellHeight);returnwww.sm136.comwbF.cellHeight;}

-(BOOL)prefersStatusBarHidden{returnYES;}@end

四、补充说明

由于系统提供的tableview可能并不能满足我们的开发需求,所以经常要求我们能够自定义tableview。

自定义tableview有两种方式,一种是使用xib创建,一种是使用纯代码的方式创建。

对于样式一样的tableview,通常使用xib进行创建,对于高度不一样,内容也不完全一致的通常使用纯代码进行自定义。























献花(0)
+1
(本文系白狐一梦首藏)