Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to use an UISearchDisplayController on UIViewController, that includes an UITableView.
I use Autolayout. When i try to put the SearchBar (_searchBar) in the tableHeaderView with

self.tableView.tableHeaderView = _searchBar;

I get the error 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'

Disabling Autolayout, the error disappears, but i need Autolayout...

The error appears, when I use Custom Cells or StandardCells...

The error appears, when the TableView has no rows...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
506 views
Welcome To Ask or Share your Answers For Others

1 Answer

As a general solution to this problem, or at least a way of finding the cause of it:

  • Turn on exception breakpoints
  • Subclass UITableView and override layoutSublayersOfLayer:, just calling super
  • Run your app - you will stop in your new method
  • In the debugger, type po [self _autolayoutTrace]

This will show you a printout of every view in the window, with the views where auto layout has not been able to come up with a solution highlighted by asterisks or AMBIGUOUS LAYOUT. These are the views you need to investigate the constraints for.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...