我之前跟着一个教程来了解故事板的基础知识,并将该代码用作编写正在编写的应用程序的参考。我想测试我的原型单元格布局,但即使我在viewDidLoad中为数组设置了值,它仍然拒绝显示任何内容。iOS Swift Dequeued可重用单元格不显示
import UIKit
class DetailViewController: UIViewController {
var cards = [Card]()
@IBOutlet weak var cardsTableView: UITableView!
@IBOutlet weak var detailDescriptionLabel: UILabel!
var detailItem: AnyObject? {
didSet {
// Update the view.
self.configureView()
}
}
func configureView() {
// Update the user interface for the detail item.
if let detail: AnyObject = self.detailItem {
if let label = self.detailDescriptionLabel {
label.text = detail.description
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cards.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//példányosítunk egy cellát
let cell = tableView.dequeueReusableCellWithIdentifier("CardCell", forIndexPath: indexPath) as CardCell
//kivesszük a sor adatait a listából
let card : Card = self.cards[indexPath.row]
cell.setCardNumber(card.number)
cell.layer.cornerRadius = 8
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
self.cards = [Card(number: 123456789,type: 1)]
dispatch_async(dispatch_get_main_queue(), {
self.cardsTableView.reloadData()
})
self.configureView()
}
}
我从一个主从结构开始,我班里的细节场景,以DetailViewController和类标识符原型的设置CardCell
class Card{
let number: Int
let type: Int
init(number: Int, type: Int){
self.number = number
self.type = type
}
}
import UIKit
class CardCell: UITableViewCell {
@IBOutlet weak var cardNumber: UILabel!
func setCardNumber(number: Int){
cardNumber.text = String(number)
}
}
我敢肯定,这是基本的东西,但是我现在第二天一直在搞这个。任何建议表示赞赏。
当你点击在故事板的原型电池,并期待在属性检查器中,你有没有'CardCell'重用更多声明标识符进入了吗? – 2015-02-24 12:23:26
IBOutlet是否连接到故事板?您的故事板中的原型单元是否属于CardCell类? – 2015-02-24 12:23:46
是的,是的,是的。 – 2015-02-24 12:47:33