セル内にUIWebViewを持つカスタムUITableViewCellがあります。 UIWebViewにはデフォルトの高さ制約(20ピクセル)があります。ロード後にUITableViewCellの高さを変更します。
class TableViewCell: UITableViewCell, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var webViewHeight: NSLayoutConstraint!
func webViewDidFinishLoad(webView: UIWebView) {
webView.frame.size.height = 1
var contentSize = webView.scrollView.contentSize
webView.frame.size.height = contentSize.height
webView.scrollView.frame.size.height = contentSize.height
webViewHeight.constant = contentSize.height
}
}
次に、私はWebViewにロードしたいものを設定します。 UIWebViewDelegateをロードした後にwebViewDidFinishLoad
を呼び出し、高さの制約を変更します。そして、現時点では、デバッグ領域に制約があります。
2016-07-06 09:11:20.492 TEST CELL[1746:56476] 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:0x7fbc087088f0 V:[UIWebView:0x7fbc0871eb70(50)]>",
"<NSLayoutConstraint:0x7fbc086b46f0 UIWebView:0x7fbc0871eb70.top == UITableViewCellContentView:0x7fbc0871dea0.topMargin>",
"<NSLayoutConstraint:0x7fbc086b4740 UITableViewCellContentView:0x7fbc0871dea0.bottomMargin == UIWebView:0x7fbc0871eb70.bottom>",
"<NSLayoutConstraint:0x7fbc08700c10 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbc0871dea0(59)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fbc087088f0 V:[UIWebView:0x7fbc0871eb70(50)]>
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.
ロード後に新しい制約定数を正しく設定する方法はありますか?
制約に関して表示されるエラーは何ですか? – SArnab
エラー内容を編集した質問内容を編集しました。 –
私はあなたの問題を解決することができます。どこからでも59 pxの制約がありますか?削除してみてください...また、[cell layoutIfNeeded]を書くことを忘れないでください。制約に新しい値を割り当てた後。 –