Why am I getting a “Auto Layout still required after executing -layoutSubviews” error every time my app launches now?

前端 未结 9 792
盖世英雄少女心
盖世英雄少女心 2020-12-11 01:11

Since I added the following code, every time my app opens this UITableViewController it crashes:

 self.noArticlesView = [[UIView alloc] init];
          


        
相关标签:
9条回答
  • 2020-12-11 01:20

    [self.view layoutIfNeeded]

    Hope this helps

    0 讨论(0)
  • 2020-12-11 01:21

    Checkout "Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass as the question appears to be the same.

    I was able to implement the category mentioned in one of the answers which solved the problem for me. However, I had to create the category on the UITableView class instead of the UITableViewCell class as is discussed in that particular answer.

    0 讨论(0)
  • 2020-12-11 01:23

    Had the same problem. Added view(s) to self.tableView and used constraints. Do not add the views to the table view via addSubview: but add them as header(s), footer(s) or cells.

    0 讨论(0)
  • 2020-12-11 01:27

    I was subclassing UIScrollView and received the same error message on iOS 7 (but not 8).

    I was overriding layoutSubviews in a manner similar to the following:

    - (void)layoutSubviews {
        [super layoutSubviews];
        // code to scroll the view
    }
    

    I resolved the issue by moving the call to super's layoutSubviews to be the last thing in the method:

    - (void)layoutSubviews {
        // code to scroll the view
        [super layoutSubviews];
    }
    
    0 讨论(0)
  • 2020-12-11 01:30

    for me is was this

    self.tableView.backgroundView = self.emptyView;
    

    I changed to this

        NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"8.0" options: NSNumericSearch];
    if (order == NSOrderedSame || order == NSOrderedDescending) {
        // OS version >= 8.0
        self.tableView.backgroundView = self.emptyView;
    }else{
        [self.tableView.backgroundView addSubview:self.emptyView];
    }
    
    0 讨论(0)
  • 2020-12-11 01:30

    I unchecked auto layout on the view controller the crash is not occurring now

    0 讨论(0)
提交回复
热议问题