[問題] table view cell 動態高度與元件

看板MacDev作者 (skill)時間11年前 (2014/01/13 12:18), 編輯推噓2(207)
留言9則, 3人參與, 最新討論串1/1
我有一個 table view 客製化了 cell cell 內有三個UI元件,如下 ┌──────────┐ │(1) 動態圖片高度 │ │ │ │(2) 動態文字高度 │ │ │ │(3) 固定文字高度 │ └──────────┘ 其中 (2) 還有可能是沒有的...orz 當三個都存在的時候,我用這一篇可以做到 (但是(2)是寫死高度的...orz) http://blog.changyy.org/2012/08/ios-interface-builder-uitableviewcell.html 我不知道要如何在(2)可能會有多行文字或者沒有文字的情況下 算出cell 的高度 並使cell 的layout不會跑掉QQ 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.21.125.247

01/13 13:09, , 1F
(2) 沒有文字,動態算出來height不就是0嗎?
01/13 13:09, 1F

01/13 13:34, , 2F
(2) 的話我是用固定高度@@|||
01/13 13:34, 2F

01/13 13:35, , 3F
因為1) 2) 3) 的間距要保持固定,但我從xib不了解要
01/13 13:35, 3F

01/13 13:36, , 4F
怎樣設定才會達成這樣的條件QQ
01/13 13:36, 4F

01/13 13:51, , 5F
autosizing? http://ppt.cc/xxYL
01/13 13:51, 5F

01/13 14:05, , 6F
我是用autolayout @@
01/13 14:05, 6F
我後來在 cell 裡的 layoutSubviews 給覆寫 -(void) layoutSubviews{ self.動態文字.frame = CGRectMake(x,x,x,x); } 結果也沒反應@@||| ※ 編輯: issuemylove 來自: 211.21.125.247 (01/13 16:07)

01/13 17:29, , 7F
- (CGFloat)tableView:(UITableView *)tableView
01/13 17:29, 7F

01/13 17:30, , 8F
heightForRowAtIndexPath:(NSIndexPath *)indexPath
01/13 17:30, 8F

01/13 17:30, , 9F
決定cell的高度
01/13 17:30, 9F
這個我知道@@ 主要是因為它有兩個變動長度 height我是算得出來 但我不知道要怎樣做設定 (依序畫出動態圖片、動態文字) 我最剛開始用 xib 但aotolayout我不知道要怎樣設定 弄不好orz ※ 編輯: issuemylove 來自: 211.21.125.247 (01/13 17:51) 後來我發現光是 image就很難把它固定位置 ┌─────────┐ │┌───────┐│ ││ 圖片高度動態 ││ │└───────┘│ │ │ ... └─────────┘ 我主要是設定了 (a) pin -> Leading space to superview (b) pin -> trailing space to superview (c) pin -> top space to superview 因為高度不固定,所以我沒設定 但也因此出現了warning: Ambiguous layout: height is ambiguous for image view. 可是就高度不固定啊~"~ 這樣要怎樣解決呢QQ||| 阿 找到這一篇有解答 http://forums.macrumors.com/showthread.php?t=1489373 ※ 編輯: issuemylove 來自: 211.21.125.247 (01/13 19:34) ※ 編輯: issuemylove 來自: 211.21.125.247 (01/13 19:39)
文章代碼(AID): #1IqsaU5A (MacDev)
文章代碼(AID): #1IqsaU5A (MacDev)