具有自定义视图的可扩展和可折叠的UITableViewCell [英] Expandable and Collapsable UITableViewCell with Custom Views

查看:117
本文介绍了具有自定义视图的可扩展和可折叠的UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对如何解决这个问题没有任何想法....

Not Getting any Idea on how to solve this ....

好的。这是我的自定义 UITableViewCell ,包含三个不同的子视图。您可以看到不同的颜色。

Ok. This is my custom UITableViewCell with three different Child Views. That you can see with different colors.

此处,我的第二个子视图高度是动态的,并在运行时计算。我使用 -heightForRowAtIndexPath 来设置 UITableViewCell 的高度。

Here , Height of my second Child View is dynamic and be calculated at run time. I am using -heightForRowAtIndexPath to set the height of UITableViewCell.

我尝试了什么:

我设置子视图的出口,然后在 -heightForRowAtIndexPath ,我用过这个代码......

I set the Outlets of Child Views and then in -heightForRowAtIndexPath , I used this Code...

middleView.frame = CGRectMake(0, 60.0, 750.0, size);
footerView.frame = CGRectMake(0, size + 60.0, 750.0, 50.0);

其中,size =动态计算中间视图的高度。

where, size = Dynamically Calculated Height of Middle View.

更新

我也尝试过这样的大小静态值...

I have also tried with static value of size like this ...

 middleView.frame = CGRectMake(0, 60.0, 750.0, 350.0);
 footerView.frame = CGRectMake(0, 350.0 + 60.0, 750.0, 50.0);

但总无运气....

大小的计算方法如下: size =(elements * 30)+ 50;

Size is calculated by this : size = (elements * 30) + 50;

其中,元素=数组中元素的数量。

where , elements = Number of elements in the Array.

问题:

看,在截图。

任何建议?

推荐答案

使用以下方法设置中间视图和页脚视图框架而不是heightForRowAtIndexPath:

Set your middle view and footer view frame in following method instead of heightForRowAtIndexPath:

并保留上面indra Mohan给出的其他方法。

and keep your other method as given by indra Mohan above.

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath       *)indexPath
{   
NSString * cellIdentifier = @"TableViewCellIdentifier"  ;
InAppTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

cell.delegate = self;
float size = [self heightForMiddleViewAtIndexPath: indexPath]
cell.middleView.frame = CGRectMake(0, 60.0, 750.0, size);
cell.footerView.frame = CGRectMake(0, size + 60.0, 750.0, 50.0);
return cell;

}

这篇关于具有自定义视图的可扩展和可折叠的UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆