2015-12-04 56 views
0

步驟:iOS的自動版式的問題:無法同時滿足的約束

  1. 我有一個網頁在兩次的tableview,但一次顯示一個的tableView;
  2. 我創建了一個查看tableview的標題視圖(稱爲 headerView);
  3. 我設置headerView當前的tableView(A)作爲 tableHeaderView,以及用於另一的tableView(B)作爲 tableHeaderView(節目A)設定爲零;
  4. 我點擊一個按鈕顯示的tableView(B),所以我設置爲零作爲 tableHeaderView爲的tableView(A),設置headerView作爲 tableHeaderView爲的tableView(B);

當我爲tableView(N)設置headerView錯誤即將到來,詳情請看下面的日誌。 控制檯錯誤日誌如下:

2015-12-04 10:15:18.777 XXXApp[1223:360705] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
     (1) look at each constraint and try to figure out which you don't expect; 
     (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x7f8f7bdd74b0 H:|-(10)-[UIView:0x7f8f7bdbbe00] (Names: '|':MarketGoodsDetail:0x7f8f7bdb92d0)>", 
    "<NSLayoutConstraint:0x7f8f7bdd7500 H:[UIView:0x7f8f7bdbbe00]-(10)-| (Names: '|':MarketGoodsDetail:0x7f8f7bdb92d0)>", 
    "<NSLayoutConstraint:0x7f8f7bdd8fa0 H:|-(0)-[MarketGoodsDetail:0x7f8f7bdb92d0] (Names: '|':UIView:0x7f8f7bdd8b70)>", 
    "<NSLayoutConstraint:0x7f8f7bdd8ff0 H:[MarketGoodsDetail:0x7f8f7bdb92d0]-(0)-| (Names: '|':UIView:0x7f8f7bdd8b70)>", 
    "<NSLayoutConstraint:0x7f8f7bddac40 H:[UIView:0x7f8f7bdd8b70]-(0)-| (Names: '|':UIView:0x7f8f7bdda860)>", 
    "<NSLayoutConstraint:0x7f8f7bddace0 H:|-(0)-[UIView:0x7f8f7bdd8b70] (Names: '|':UIView:0x7f8f7bdda860)>", 
    "<NSLayoutConstraint:0x7f8f7e0c6d90 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f8f7bdda860(0)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8f7bdd7500 H:[UIView:0x7f8f7bdbbe00]-(10)-| (Names: '|':MarketGoodsDetail:0x7f8f7bdb92d0)> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

由於傑森 - 賈勒特的博客http://staxmanade.com/2015/06/debugging-ios-autolayout-issues/我打印,我認爲它造成如下問題的看法的自動佈局信息:

po [0x7f8f7bdb92d0 recursiveDescription] 
<MarketGoodsDetail: 0x7f8f7bdb92d0; frame = (0 0; 375 127); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7f8f7bdb9760>> 
    | <UILabel: 0x7f8f7bdb9b80; frame = (10 8.5; 37.5 12); text = '(廣貴所)'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdb9780>> 
    | | <_UILabelContentLayer: 0x7f8f7bfc4090> (layer) 
    | <UILabel: 0x7f8f7bdba820; frame = (10 22.5; 121.5 36); text = '2892.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdb9f10>> 
    | <UILabel: 0x7f8f7bdbb460; frame = (237.5 35; 52.5 20.5); text = '-13.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbb660>> 
    | <UILabel: 0x7f8f7bdbb9c0; frame = (307 35; 58 20.5); text = '-0.45%'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbbbc0>> 
    | <UIView: 0x7f8f7bdbbe00; frame = (10 63.5; 355 0.5); autoresize = RM+BM; layer = <CALayer: 0x7f8f7bdbbf70>> 
    | <UILabel: 0x7f8f7bdbc0b0; frame = (10 76; 26 16); text = '今開'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbc2b0>> 
    | | <_UILabelContentLayer: 0x7f8f7e0c2a90> (layer) 
    | <UILabel: 0x7f8f7bdbcd70; frame = (42 76; 51.5 16); text = '2905.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbcf70>> 
    | <UILabel: 0x7f8f7bdbd180; frame = (10 102; 26 16); text = '昨收'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbd380>> 
    | | <_UILabelContentLayer: 0x7f8f7e0c1640> (layer) 
    | <UILabel: 0x7f8f7bdbd590; frame = (42 102; 51.5 16); text = '2905.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbd790>> 
    | <UILabel: 0x7f8f7bdbd9a0; frame = (281.5 76; 26 16); text = '最高'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbdba0>> 
    | | <_UILabelContentLayer: 0x7f8f7e0c1ea0> (layer) 
    | <UILabel: 0x7f8f7bdbddb0; frame = (313.5 76; 51.5 16); text = '2909.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbdfb0>> 
    | <UILabel: 0x7f8f7bdbe1c0; frame = (281.5 102; 26 16); text = '最低'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbe3c0>> 
    | | <_UILabelContentLayer: 0x7f8f7e0c4e60> (layer) 
    | <UILabel: 0x7f8f7bdbe5d0; frame = (313.5 102; 51.5 16); text = '2889.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbe7d0>> 
    | <UIView: 0x7f8f7bdbe9e0; frame = (146 76; 83.5 42); autoresize = RM+BM; layer = <CALayer: 0x7f8f7bdbeb50>> 
    | | <UILabel: 0x7f8f7bdbeb70; frame = (0 0; 26 16); text = '買進'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbed70>> 
    | | | <_UILabelContentLayer: 0x7f8f7e0c4e90> (layer) 
    | | <UILabel: 0x7f8f7bdbef80; frame = (0 26; 26 16); text = '賣出'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdd5990>> 
    | | | <_UILabelContentLayer: 0x7f8f7e0c4b70> (layer) 
    | | <UILabel: 0x7f8f7bdd5b80; frame = (32 0; 51.5 16); text = '2898.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdd5d80>> 
    | | <UILabel: 0x7f8f7bdd5f90; frame = (32 26; 51.5 16); text = '2892.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdd6190>> 

它是超級視圖自動佈局:

po [[0x7f8f7bdb92d0 superview] recursiveDescription] 
<UIView: 0x7f8f7bdd8b70; frame = (0 0; 375 127); autoresize = RM+BM; layer = <CALayer: 0x7f8f7bdd8ce0>> 
    | <MarketGoodsDetail: 0x7f8f7bdb92d0; frame = (0 0; 375 127); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7f8f7bdb9760>> 
    | | <UILabel: 0x7f8f7bdb9b80; frame = (10 8.5; 37.5 12); text = '(廣貴所)'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdb9780>> 
    | | | <_UILabelContentLayer: 0x7f8f7bfc4090> (layer) 
    | | <UILabel: 0x7f8f7bdba820; frame = (10 22.5; 121.5 36); text = '2892.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdb9f10>> 
    | | <UILabel: 0x7f8f7bdbb460; frame = (237.5 35; 52.5 20.5); text = '-13.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbb660>> 
    | | <UILabel: 0x7f8f7bdbb9c0; frame = (307 35; 58 20.5); text = '-0.45%'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbbbc0>> 
    | | <UIView: 0x7f8f7bdbbe00; frame = (10 63.5; 355 0.5); autoresize = RM+BM; layer = <CALayer: 0x7f8f7bdbbf70>> 
    | | <UILabel: 0x7f8f7bdbc0b0; frame = (10 76; 26 16); text = '今開'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbc2b0>> 
    | | | <_UILabelContentLayer: 0x7f8f7e0c2a90> (layer) 
    | | <UILabel: 0x7f8f7bdbcd70; frame = (42 76; 51.5 16); text = '2905.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbcf70>> 
    | | <UILabel: 0x7f8f7bdbd180; frame = (10 102; 26 16); text = '昨收'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbd380>> 
    | | | <_UILabelContentLayer: 0x7f8f7e0c1640> (layer) 
    | | <UILabel: 0x7f8f7bdbd590; frame = (42 102; 51.5 16); text = '2905.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbd790>> 
    | | <UILabel: 0x7f8f7bdbd9a0; frame = (281.5 76; 26 16); text = '最高'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbdba0>> 
    | | | <_UILabelContentLayer: 0x7f8f7e0c1ea0> (layer) 
    | | <UILabel: 0x7f8f7bdbddb0; frame = (313.5 76; 51.5 16); text = '2909.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbdfb0>> 
    | | <UILabel: 0x7f8f7bdbe1c0; frame = (281.5 102; 26 16); text = '最低'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbe3c0>> 
    | | | <_UILabelContentLayer: 0x7f8f7e0c4e60> (layer) 
    | | <UILabel: 0x7f8f7bdbe5d0; frame = (313.5 102; 51.5 16); text = '2889.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbe7d0>> 
    | | <UIView: 0x7f8f7bdbe9e0; frame = (146 76; 83.5 42); autoresize = RM+BM; layer = <CALayer: 0x7f8f7bdbeb50>> 
    | | | <UILabel: 0x7f8f7bdbeb70; frame = (0 0; 26 16); text = '買進'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdbed70>> 
    | | | | <_UILabelContentLayer: 0x7f8f7e0c4e90> (layer) 
    | | | <UILabel: 0x7f8f7bdbef80; frame = (0 26; 26 16); text = '賣出'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdd5990>> 
    | | | | <_UILabelContentLayer: 0x7f8f7e0c4b70> (layer) 
    | | | <UILabel: 0x7f8f7bdd5b80; frame = (32 0; 51.5 16); text = '2898.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdd5d80>> 
    | | | <UILabel: 0x7f8f7bdd5f90; frame = (32 26; 51.5 16); text = '2892.00'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7f8f7bdd6190>> 

誰能告訴我哪個約束導致了這個問題?感謝您的幫助!

+0

視圖是否正確顯示,並且您希望錯誤消失還是未按照您希望的方式顯示? – beyowulf

+0

@beyowulf視圖呈現正確,但報告錯誤信息我張貼,如何讓錯誤消失? – Raniys

+0

你怎麼隱藏你不想展示的表格視圖?偶然設置它的寬度爲0嗎? – kleezy

回答

2

我想你想的這些限制因素的優先級設置爲999:

"<NSLayoutConstraint:0x7f8f7e0c6d90 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f8f7bdda860(0)]>" 

指定你的容器視圖的寬度將是0:

"<NSLayoutConstraint:0x7f8f7bdd74b0 H:|-(10)-[UIView:0x7f8f7bdbbe00] (Names: '|':MarketGoodsDetail:0x7f8f7bdb92d0)>", 
"<NSLayoutConstraint:0x7f8f7bdd7500 H:[UIView:0x7f8f7bdbbe00]-(10)-| (Names: '|':MarketGoodsDetail:0x7f8f7bdb92d0)>" 

我相信那些相互矛盾點。所以它不能添加10點邊距(上面兩個約束要求)。將它們設置爲999應該讓它們優雅地被覆蓋。

有關更多信息,請參見What is a 'UIView-Encapsulated-Layout-Width' constraint?

+0

如何將它們的優先級設置爲999?在故事板或代碼中? – Raniys

+0

如果您在故事板中設置了約束條件,那麼您可以在那裏編輯它們。您需要找到一個視圖,該視圖是您的MarketGoodsDetail視圖的前導/尾隨約束設置爲10的直接子視圖。對於每個視圖,請單擊約束上的編輯並將1000優先級更改爲999. – kleezy

+0

您拯救了我的生命。 – Raniys

相關問題