求助 关于ios8 tableViewCell 自动化ios8 cell自适应高度度的问题

iphone开发之UITableViewCell自适应高度
时间: 18:50:04
如果不能确定tableViewCell的内容,就不能设定cell的高度
通常情况下,tableViewCell中会包含label,textview等控件,这时我们可以使用[@&& sizeWithFont:&#(UIFont *)#& constrainedToSize:&#(CGSize)#& lineBreakMode:&#(NSLineBreakMode)#&]
来获取label的高度,然后在- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = (FootPrintCell *)[self tableView:self.tableview cellForRowAtIndexPath:indexPath];
// cell.label.height...
修改高度。
如果包含UITextView更好办,可以通过cell.textview.contentSize,得到textview的高度,然后通过上述方法重新设定cell的高度。
有问题请留言,大家一起交流学习!
说明:转载请注明出处!
$T.total > 0 && $T.page <= $T.pageNum}
{#foreach $T.data as r}
{$T.r.formt_tm}{#if $T.r.nickname}{#else}匿名{#/if}
{$T.r.content}
{#if $T.page > 1 && $T.pageNum > 1)
$T.s_num > 2}
{#for index = $T.s_num to $T.e_num}
$T.pageNum > $T.pageNavSize+ 2 && $T.s_num != $T.pageNum - $T.pageNavSize}
{#if $T.pageNum > 1}
{#if $T.pageNum != $T.page && $T.pageNum > 1}
<a href="javascript:void(0);" page="{$T.page 下一页
您的回应...
也许你感兴趣
(window.slotbydup=window.slotbydup || []).push({
id: '2803163',
container: s,
size: '120,270',
display: 'float'
(C)2012 本站提供的内容来源于广大网络用户,我们不保证内容的正确性。如果转载了您的内容,希望删除的请联系我们!求助 关于ios8 tableViewCell 自动化适应高度的问题_百度知道今天看啥 热点:
iOS 8 Tableview根据AutoLayout自动调整高度,iostableview高度
原创Blog,转载请注明出处
blog.csdn.net/hello_hwc
前言:在iOS 8之前,如果要让Tableview根据内容自动调整大小的话,需要动态的去计算每个cell的高度。太尼玛操蛋了。iOS 8之后,可以根据AutoLayout来自动调整高度了,原理很简单。
DataSource中选择让iOS自动计算
在Cell中,设定能够让iOS计算出高度的AutoLayout,注意,这里一定要是能够计算出高度的AutoLayout,这和传统的不一样。
新建一个基于singleview的工程,然后删除默认Storyboard的ViewController,拖拽一个TableviewController,设置为inital Controller
往Prototype Cells上拖拽两个UILabel
设置cell 的reuse identifier为cell
为两个Label设置属性
设置tag为10
设置tag为11
为两个Label设置AutoLayout
注意,这里把title放在左上角,Detail放在左下角。然后添加二者之间的距离恒定为1,那么AutoLayout就会自动计算出高度。
新建一个TableviewController,并且讲storyboard上的tableviewController设置为新建的类
设置Tableview的高度为自动获取
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticD
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticD
加入存储数据的数组,并且在初始化里设定数据
@property (strong,nonatomic)NSArray * titleA
@property (strong,nonatomic)NSArray * detailA
- (void)viewDidLoad {
[super viewDidLoad];
self.titleArray = @[@"1",@"2",@"3"];
self.detailArray = @[@"shot",@"Aduahguhauhguhaudghuahguhudhauhg",@"dhuahgudhaughuahdughuahguhauhguhdahudhuahughduahguhadguhaduhguadhughduahguahguhadugh"];
接下来就是Tablview的常用的,很好理解,这里不多赘述
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.titleArray.count;
-(BOOL)prefersStatusBarHidden{
return true;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
UILabel * titleLabel = (UILabel *)[cell viewWithTag:10];
UILabel * contentLabel = (UILabel *)[cell viewWithTag:11];
titleLabel.text = self.titleArray[indexPath.row];
contentLabel.text = self.detailArray[indexPath.row];
contentLabel.numberOfLines = 0;
然后,就得到了我们想要的效果了。
相关搜索:
相关阅读:
相关频道:
Android教程最近更新求助 关于ios8 tableViewCell 自动化适应高度的问题_百度知道

我要回帖

更多关于 collectioncell自适应 的文章

 

随机推荐