1

我使用動態單元格高度的自動佈局方法,如Using Auto Layout in UITableView for dynamic cell layouts & variable row heights中所述。這工作到目前爲止。現在我在UIPopoverController中介紹我的UITableView也是有效的。現在到有趣的部分:我從不同的視圖控制器呈現這個popover。在第一個視圖控制器上,一切都按預期工作。如果我切換到第二個視圖控制器,它也提供了這種酥料餅的酥料餅完全是空的(即使沒有分割線!),我收到以下錯誤:根據自動調整掩碼,UITableViewCellContentView寬度始終爲零(僅在iOS 7上)

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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7a706fa0 H:|-(8)-[UILabel:0x7a707760] (Names: '|':UITableViewCellContentView:0x7a707ba0)>", 
    "<NSLayoutConstraint:0x7a707060 H:[UILabel:0x7a707760]-(8)-| (Names: '|':UITableViewCellContentView:0x7a707ba0)>", 
    "<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7a707060 H:[UILabel:0x7a707760]-(8)-| (Names: '|':UITableViewCellContentView:0x7a707ba0)> 

Break on objc_exception_throw to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

現在我們要注意這部分:

"<NSAutoresizingMaskLayoutConstraint:0x7a706970 h=--& v=--& H:[UITableViewCellContentView:0x7a707ba0(0)]>" 

它說根據自動調整掩碼,UITableViewCellContentView的寬度爲零。但相同的代碼之前在另一個視圖控制器上工作。 popover應該獨立於我在視圖控制器中的設置。我試圖複製另一個項目中的行爲,但我不能。這也只出現在iOS 7上。在iOS 8上,一切正常。我也試圖離開自動佈局,然後顯示內容(但不是我想要的方式)。我能想出的唯一選擇是回到spring和struts ...如果你想我可以用C#提供我的代碼,但我放棄了它,使問題更具可讀性。

這可能是什麼原因?有沒有人經歷過這樣的事情?

回答

2

經過一天的搜索後,原因可能是默認的錯誤。因爲我以前沒有控制器的酥料餅的下面一行代碼仍然存在:

myViewControllerInPopup.View.TranslatesAutoresizingMaskIntoConstraints = false; 

我有這裏面實例化的酥料餅的視圖控制器上。刪除這條線,一切按預期工作。