简体   繁体   English

在iOS 7中在viewDidLayoutSubviews应用中设置新的Tableview框架时崩溃

[英]When set new frame of tableview in viewDidLayoutSubviews app crashes in iOS 7

- (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];
}

This method works perfectly in iOS 8 but crashes in iOS 7 , this crashes come from nowhere. 此方法在iOS 8中完美运行,但在iOS 7中崩溃,这种崩溃无处不在。

I got the same problem while manually adding constraints in code. 在代码中手动添加约束时遇到了相同的问题。 In code, I was doing the following: From what I can tell, the issue is that when you disable translatesAutoresizingMaskIntoConstraints Solution: My solution was to move everything to the contentView. 在代码中,我正在执行以下操作:据我所知,问题是当您禁用了translatesAutoresizingMaskIntoConstraints解决方案:我的解决方案是将所有内容移至contentView。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM