我在我的UITableView面臨一個非常奇怪的問題。 我有一些不同的單元格,我想在新聞推送式表格視圖上顯示。UITableViewCellContentView高度如何可能不同於heightForRowAtIndexPath:
我在重用後遇到單元問題。 單元格包含兩個圖像,兩個標籤和一個帶有share/like/comment按鈕的視圖。 我嘗試要畫它,但我不知道這會是相當:
-------------------------------------------------
| | __ ____________________________ |
| | |_2| | | |
| | | 3 | |
| | | | |
| 1 | |____________________________| |
| | |
| |_______________________________________|
| | |
| | 4 |
|_______|_______________________________________|
| |
| 5 |
|_______________________________________________|
1 : objectImage
2 : subjectImage
3 : titleLabel
4 : commentLabel
5 : actionsView
我的約束是:
"H:|-0-[objectImage(60)]-7-[subjectImage(30)]-7-[titleLabel]-7-|"
"H:|-0-[objectImage(60)]-0-[commentLabel]-0-|"
"H:|-0-[actionsView]-0-|"
"V:|-0-[objectImage(>=35)]-0-[actionsView(44)]-0-|"
"V:|-7-[subjectImage(30)]"
"V:|-7-[titleLabel(>=46)]-7-[commentLabel(>=35)]-0-[actionsView(44)]-0-|"
而且每個細胞繪製的時候,我改變這個約束:
"V:[commentLabel(%0.2f)]"
細胞第一次顯示完美。
但是,我遇到的問題是,在一些重用(我無法每次重現它)之後,應用程序因爲約束問題而崩潰。 這裏是例外:
"<NSLayoutConstraint:0x205a75b0 V:[UILabel:0x1ef31430(105)]>",
"<NSLayoutConstraint:0x1ef34440 V:[UILabel:0x1ef31430]-(0)-[UIView:0x1ef2fe50]>",
"<NSLayoutConstraint:0x1ef34380 V:[UILabel:0x1ef31250]-(7)-[UILabel:0x1ef31430]>",
"<NSLayoutConstraint:0x1ef33900 V:|-(7)-[UILabel:0x1ef31250] (Names: '|':UITableViewCellContentView:0x1ef2bf50)>",
"<NSLayoutConstraint:0x1ef34340 V:[UILabel:0x1ef31250(>=46)]>",
"<NSLayoutConstraint:0x1efV:[UIView:0x1ef2fe50]-(0)-| (Names: '|':UITableViewCellContentView:0x1ef2bf50)>",
"<NSLayoutConstraint:0x1ef331d0 V:[UIView:0x1ef2fe50(44)]>",
"<NSAutoresizingMaskLayoutConstraint:0x1ef36f90 h=--& v=--& V:[UITableViewCellContentView:0x1ef2bf50(147)]>"
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1ef34380 V:[UILabel:0x1ef31250]-(7)-[UILabel:0x1ef31430]>
的問題是,該約束[UITableViewCellContentView:0x1ef2bf50(147)]是不正確的。
是什麼奇怪的是,heightForRowAtIndexPath:返回正確的值是217
什麼我不明白的是,的UITableViewCell的高度是正確的!
(lldb) po 0x1ef2bf50
$0 = 519225168 <UITableViewCellContentView: 0x1ef2bf50; frame = (0 0; 320 147); gestureRecognizers = <NSArray: 0x1ef30a20>; layer = <CALayer: 0x1ef2a3d0>>
(lldb) po [0x1ef2bf50 superview]
$1 = 0x1ef30e40 <NewsSubjectCommentCell: 0x1ef30e40; baseClass = UITableViewCell; frame = (0 1055; 320 217); hidden = YES; autoresize = W; layer = <CALayer: 0x1ef25e10>>
所以我不明白這怎麼可能是UITableViewCellContentView的高度限制爲147,是同類型的另一小區的高度,但它應改爲209,對不對?因此,如果你對這種情況如何發生有所瞭解(也許我做錯了什麼),我會很高興。
感謝,
你找到一個解決方案?我有完全相同的問題。 –
否,我使用的(差)的解決方案是在heightForRowAtIndexPath 1添加到細胞高度:功能 –
http://stackoverflow.com/questions/12610783/auto-layout-still-required-after-executing-layoutsubviews- with-uitableviewcel/39136021#39136021 – qingqinghebiancao