【问题标题】:UITableView fine in iOS 8 but collapsed in iOS7UITableView 在 iOS 8 中很好,但在 iOS7 中崩溃了
【发布时间】:2015-11-02 09:33:51
【问题描述】:

我一直在看这个iOS应用程序,基本上iOS8中的表格都很好,但是在iOS7中运行时它们都没有高度。

最初的规范要求只支持 iOS8,但由于一些客户只要求 iPhone 4s 向后兼容。下面是正在发生的事情的屏幕截图。任何帮助都会很棒。

在 viewDidLoad

self.myTableView.estimatedRowHeight = 140.0;
self.myTableView.rowHeight = UITableViewAutomaticDimension;

还有这个功能:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:   
                                          (NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

在情节提要中,正在折叠的单元格只是基本单元格。具有以下属性:

【问题讨论】:

  • 只有iOS 8及以后版本支持UITableViewAutomaticDimension
  • UITableViewAutomaticDimension 是 iOS 8 之前的版本
  • 您必须有条件地更改heightForRowAtIndexPath中表格视图单元格的高度

标签: ios objective-c uitableview ios7 ios8


【解决方案1】:

有条件地改变大小

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=8.0)
    {
        return UITableViewAutomaticDimension;
    }
    else{
        //Calulate size of cell and return it from here. like as
        return 40;
    }
}

【讨论】:

  • 好的,谢谢。对于像这样的简单页面,效果很好,但是动态单元格高度页面我必须在 else 中做很多工作。
  • @KevinMann 是的,您必须计算每个标签的文本大小以及所有内容。 iOS 8 提供了强大的功能:)
  • 我将不得不等待 5 分钟才能完成。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多