3 回答

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊
這適用于使用.xib工作的自定義單元格
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ let identifier = "Custom" var cell: CustomCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? CustomCel if cell == nil { tableView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: identifier) cell =tableView.dequeueReusableCellWithIdentifier(identifier) as? CustomCell }return cell}

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊
我也有同樣的問(wèn)題。
一般來(lái)說(shuō),我做的和你一樣。
class dynamicCell: UITableViewCell { @IBOutlet var testLabel : UILabel init(style: UITableViewCellStyle, reuseIdentifier: String) { super.init(style: style, reuseIdentifier: reuseIdentifier) } override func awakeFromNib() { super.awakeFromNib() } override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) }}
并在uitableviewcell方法中:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { var cell :dynamicCell = tableView.dequeueReusableCellWithIdentifier("cell") as dynamicCell cell.testLabel.text = "so sad" println(cell.testLabel) return cell;}
是的,tableview什么都沒(méi)顯示!但是猜猜看,它實(shí)際上顯示了一些東西......因?yàn)槲覐膒rintln(cell.testLabel)獲得的日志顯示所有標(biāo)簽實(shí)際上都顯示出來(lái)了。
但!他們的框架很奇怪,有這樣的東西:
frame =(0 -21; 42 21);
所以它有一個(gè)(0,-21)為(x,y),這意味著標(biāo)簽只出現(xiàn)在單元格邊界之外的某個(gè)地方。
所以我嘗試手動(dòng)添加調(diào)整框架,如下所示:
cell.testLabel.frame = CGRectMake(10,10,42,21)
可悲的是,它不起作用。
--------------- 10分鐘后更新-----------------
我做的。所以,似乎問(wèn)題來(lái)自Size Classes。
單擊.storyboard文件,然后轉(zhuǎn)到文件檢查器選項(xiàng)卡
取消勾選“大小類”復(fù)選框
最后,我的“太悲傷”的標(biāo)簽出來(lái)了!
- 3 回答
- 0 關(guān)注
- 1177 瀏覽
添加回答
舉報(bào)