swift4です。
制約をコードで記載したいので元々xib内でつけていた制約を全て削除し、コードで書いてみました。
しかし、エラーが出てしまいます。
おそらく根本的にコードでの書き方を間違えているような気がします。
解決方法を教えてください。
UITableViewとそのcellをxibで作っています。
swift
1 2class TestView: UIView, UITableViewDelegate, UITableViewDataSource { 3 4... 5 6 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 7 /// cell生成 8 let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell", for: indexPath) as! TestTableViewCell 9 10... 11... 12... 13 /// imageViewをCellの左端から16.0の位置で固定したい。しかしERROR。 14 cell.imageView.leadingAnchor.constraint(equalTo: cell.contentView.layoutMarginsGuide.leadingAnchor, constant: 16.0).isActive = true 15 16...
画像内に制約は写っていませんが、制約は一つもつけていません。
エラー内容は下記の通りです。
swift
12018-07-20 20:46:51.193283+0900 Test[1977:743127] [Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead. 22018-07-20 20:46:51.197165+0900 Test[1977:743127] [LayoutConstraints] Unable to simultaneously satisfy constraints. 3 Probably at least one of the constraints in the following list is one you don't want. 4 Try this: 5 (1) look at each constraint and try to figure out which you don't expect; 6 (2) find the code that added the unwanted constraint or constraints and fix it. 7 (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 8( 9 "<NSAutoresizingMaskLayoutConstraint:0x1d4289970 h=--& v=--& UIImageView:0x105809e90.midX == 30 (active)>", 10 "<NSAutoresizingMaskLayoutConstraint:0x1d42899c0 h=--& v=--& UIImageView:0x105809e90.width == 18 (active)>", 11 "<NSLayoutConstraint:0x1d4289830 UIImageView:0x105809e90.leading == UILayoutGuide:0x1d41ba320'UIViewLayoutMarginsGuide'.leading + 16 (active)>", 12 "<NSAutoresizingMaskLayoutConstraint:0x1d009c020 h=--& v=--& 'UIView-Encapsulated-Layout-Left' UITableViewCellContentView:0x10580cf80.minX == 0 (active, names: '|':Test.TestTableViewCell:0x106031c00'TestTableViewCell' )>", 13 "<NSLayoutConstraint:0x1d42896a0 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x1d41ba320'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':UITableViewCellContentView:0x10580cf80 )>" 14) 15 16Will attempt to recover by breaking constraint 17<NSLayoutConstraint:0x1d4289830 UIImageView:0x105809e90.leading == UILayoutGuide:0x1d41ba320'UIViewLayoutMarginsGuide'.leading + 16 (active)> 18 19Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 20The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
なぜxib上で付けないのでしょうか?
回答1件
あなたの回答
tips
プレビュー