在viewDidLayoutSubviews中设置tableview的新框架应用程序在iOS 7中崩溃

时间:2015-05-13 06:45:18

标签: ios objective-c uitableview ios7 viewdidlayoutsubviews

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    if (employeeListModel.count > 0) {
        if ([employeeListModel count]*90 < self.view.bounds.size.height-64) {
            CGRect frame = self.empListTableView.frame;
            frame.size.height = [employeeListModel count]*90;
            self.empListTableView.frame = frame;
            //self.empListTableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, [employeeListModel count]*90);
        } else {
            self.empListTableView.frame = self.view.bounds;
        }
    }
    [self.empListTableView layoutIfNeeded];
}

这种方法在iOS 8中完美运行但在iOS 7中崩溃,这种崩溃来自任何地方。

1 个答案:

答案 0 :(得分:2)

我在代码中手动添加约束时遇到了同样的问题。在代码中,我正在做以下事情: 据我所知,问题是当你禁用translatesAutoresizingMaskIntoConstraints时 解: 我的解决方案是将所有内容移到contentView。

    {
   [self.contentView addSubview:someView];
   [self.contentView addSubview:someOtherView];
   [self.contentView addConstraint:...];
}