使用autolayout常見錯誤
1:The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x8e82e40 UISearchBar:0x8e7fa80.top == UIView:0x8b7c510.top + 20>
When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
這個錯誤是創建完searchBar以后要馬上添加到當前view中,否則添加約束的時候就會有警告。把紅線圈住的代碼移動到箭頭所指的地方就行。