自定义UITableViewCell不显示内容

时间:2014-11-25 16:35:31

标签: ios iphone uitableview swift

我设置了自定义UITableViewCell,但它没有显示任何内容。当TableView连接到默认单元格时,它显示内容。我将QuoteyTableViewCell设置为故事板中单元格的类。不知道我做错了什么,这是我的代码。谢谢:)。

  

导入UIKit

     

类KeepTableViewController:UITableViewController {

     

var keepsQuotes:Array> = [[

"quote": "Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover.",
"author" : "H. Jackson Brown Jr"],[

 "quote": "Be yourself; everyone else is already taken.",
 "author" : "Oscar Wilde"],[

 "quote": "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel.",
  "author" : "Maya Angelou"
],[

   "quote":  "If you tell the truth, you don't have to remember anything.",
    "author" : "Mark Twain"
]
 ]




override func viewDidLoad() {
    super.viewDidLoad()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return keptQuotes.count
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell : QuoteyTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath:
     

indexPath)为QuoteyTableViewCell

    // Configure the cell...

    cell.authorLabel.text = keptQuotes[indexPath.row]["author"]
    cell.quoteTextView.text = keptQuotes[indexPath.row]["quote"]

    return cell
}

和细胞类:

  

导入UIKit

     

类QuoteyTableViewCell:UITableViewCell {

@IBOutlet weak var authorLabel: UILabel!
@IBOutlet var quoteTextView: UITextView!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}
     

}

再次感谢:)

1 个答案:

答案 0 :(得分:0)

检查以下几点:

  • 故事板中TableView的Content属性设置为“Dynamic Prototypes”

  • 故事板中的原型单元格具有自定义类集

  • 故事板中的原型单元格具有正确的重用标识符集

  • tableView的datasourcedelegate属性正确绑定到TableViewController