我正在用XCode6使用swift構建iPhone應用程序。我遇到了一個問題,即添加到單元格中的標籤僅在選中單元格行時顯示。當標籤移出單元格內容視圖(例如導航欄)時,會出現標籤。默認的textLabel顯示正常,不管該行是否被選中。自定義單元格標籤只顯示行選擇
下面是一個帶有界面構建器+實際行爲截圖的imgur。它定義自定義單元格類三無靜電標籤,設置標籤文本
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PlayerSelectTableViewCell
let name = playerNames[indexPath.row]
var hrs = Int(RosterStore.sharedInstance.get(name).stats["HR"]!)
var avg = RosterStore.sharedInstance.get(name).stats["AVG"]!
var avgString = "\(avg)" as NSString
cell.hrLabel!.text = "\(hrs)"
cell.posLabel!.text = RosterStore.sharedInstance.get(name).pos
cell.avgLabel!.text = avgString.substringFromIndex(1)
cell.textLabel!.text = name
println(cell.hrLabel.text)
return cell
}
注意,我可以設置cell.textLabel這種方式和它的作品
@IBOutlet var posLabel: UILabel!
@IBOutlet var hrLabel: UILabel!
@IBOutlet var avgLabel: UILabel!
代碼。如果有幫助,textLabel將突出顯示爲藍色,而其他所有標籤都突出顯示爲綠色。
鏈接到github這裏 - https://github.com/klinskyc/OuttaHere 謝謝!
繼續前進,發佈您的代碼 – 2014-10-04 00:42:36
你有在Interface Builder中正確設置自定義類原型細胞的?您是否已將原型單元格中的標籤連接到IBOutlets? – Paulw11 2014-10-04 00:55:29
@ Paulw11我的自定義類已設置。 IBOutlet代碼是從ctrl拖動標籤自己到自定義類。我能夠正確設置並獲取標籤值。他們只顯示行被選中時顯示。我希望它們始終顯示(如默認的textLabel) – rockyroadster555 2014-10-04 00:59:36