셀 안에 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.
로드 후 올바르게 새로운 제약 조건을 어떻게 설정할 수 있습니까? TableViewCell
에서 다음의 제약 상단과 하단에 webView
를 고정하여
if (webview.isLoading) {
return
} else {
// do my stuff
}
제약 조건과 관련된 오류는 무엇입니까? – SArnab
오류 설명이있는 질문 내용을 편집했습니다. –
이 질문을 도와 주시면 문제를 해결할 수 있습니다. 셀 안에는 어떤 제약 사항이 있습니까? 어디서나 59 픽셀의 제한이 있습니까? 그것을 제거하고 시도하십시오 ... 또한 [cell layoutIfNeeded]를 쓰는 것을 잊지 마십시오; 제약에 새로운 값을 할당 한 후 –