iOS学习之路01(根据label的内容更改cell的高度)
来源:互联网 发布:德比软件 地址 编辑:程序博客网 时间:2024/06/01 20:12
UITableView的cell的绘制时的函数的调用顺序,是先调用
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
返回tableView的行,然后调用
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
最后调用
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
所以,需要先计算好cell的高度。在回调函数时返回变量就行了;#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,strong) UITableView *myTableView;
@end
@implementation ViewController
@synthesize dataArray=_dataArray;
@synthesize myTableView=_myTableView;
- (void)viewDidLoad
{
[superviewDidLoad];
_dataArray=[[NSMutableArrayalloc]initWithObjects:@"cell",
@"cellcellcell",
@"cellcellcellcellcell",
@"cellcellcellcellcellcellcell",
@"cellcellcellcellcellcellcellcellcell",
@"cellcellcellcellcellcellcellcellcellcellcell",
@"cellcellcellcellcellcellcellcellcellcellcellcellcellcell",
@"cellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcell",
@"cellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcell",
@"cellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcellcell",
nil];
_myTableView=[[UITableViewalloc]initWithFrame:CGRectMake(0,0, 320,480) style:UITableViewStylePlain];
_myTableView.delegate=self;
_myTableView.dataSource=self;
[self.viewaddSubview:_myTableView];
[UIApplicationsharedApplication].statusBarHidden=NO;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"1");
return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *indentifer=@"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:indentifer];
if (cell == nil)
{
cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell"];
UIFont *font=[UIFontsystemFontOfSize:14];
NSString *content=[_dataArrayobjectAtIndex:indexPath.row];
cell.textLabel.text=content;
cell.textLabel.numberOfLines=0;
cell.textLabel.font=font;
}
NSLog(@"2");
return cell;
}
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
int row=indexPath.row;
CGFloat contentWidth = self.view.frame.size.width;
//
UIFont *font = [UIFontsystemFontOfSize:14];
//
NSString *content = [_dataArrayobjectAtIndex:row];
//
CGSize size = [contentsizeWithFont:font constrainedToSize:CGSizeMake(contentWidth,1000.0f) lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"3");
//
return size.height+20;
}
- iOS学习之路01(根据label的内容更改cell的高度)
- 根据label的内容返回自定义cell的高度
- ios根据内容设置cell的高度
- IOS 根据cell内容设置cell的高度
- iOS 根据文字内容设置cell 的高度
- ios开发笔记之如何让tableView根据文本内容动态改变cell的高度
- 根据内容更改label的frame
- 根据内容自动调整高度的cell
- 根据文本内容计算cell的高度
- 根据内容自动调节cell的高度
- UITableView的Cell根据内容计算高度
- iOS cell 的自适应高度 中 返回label的高度
- 根据Label的文字内容动态计算Label高度
- iOS 根据字符串设置label 的高度
- iOS - 根据lable内容计算label高度
- iOS 中 cell和 label 的自适应高度
- iphone根据文本内容调整label高度的方法。
- 根据label正文内容动态计算正文的高度
- 对未来Google搜索技术的深度分析.txt
- re::engine::RE2
- iOS图像拉伸的集中方法
- regex
- 一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
- iOS学习之路01(根据label的内容更改cell的高度)
- 自己写的一个小软件日志通讯录记帐
- Premultiplied Alpha
- css盒子的浮动一
- oracle 索引扫描的几种类型
- C#笔记1——如何在登录界面设置主界面的ToolStripMenuItem的enabled属性,实现不同用户进入不同模块
- KVC的机制
- Linux下开启VNCserver服务
- java 连接mysql 和sql server2008代码