简体   繁体   English

自定义TableViewCell不显示内容

[英]Custom TableViewCell not displaying content

I have a custom UITableViewCell set up and it's not displaying any of the content. 我有一个自定义的UITableViewCell设置,它不显示任何内容。 When the TableView was hooked up to the default cell it displayed the content. 当TableView连接到默认单元格时,它将显示内容。 I have QuoteyTableViewCell set as the class for the cell in my storyboard. 我将QuoteyTableViewCell设置为情节提要中单元的类。 Not sure what I'm doing wrong, here's my code. 不知道我在做什么错,这是我的代码。 Thanks :). 谢谢 :)。

import UIKit 导入UIKit

class KeepTableViewController: UITableViewController { 类KeepTableViewController:UITableViewController {

var keptQuotes : Array> = [[ var keepQuotes: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) as QuoteyTableViewCell indexPath)作为QuoteyTableViewCell

  // Configure the cell... cell.authorLabel.text = keptQuotes[indexPath.row]["author"] cell.quoteTextView.text = keptQuotes[indexPath.row]["quote"] return cell } 

and the cell class: 和单元格类:

import UIKit 导入UIKit

class QuoteyTableViewCell: UITableViewCell { 类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 } 

} }

Thanks again :) 再次感谢 :)

Check these points: 检查以下几点:

  • The Content property of the TableView in the storyboard is set to "Dynamic Prototypes" 故事板中TableView的Content属性设置为“动态原型”

  • The prototype cell in the storyboard has the custom class set 故事板上的原型单元具有自定义类集

  • The prototype cell in the storyboard has the correct reuse identifier set 情节提要中的原型单元格具有正确的重用标识符集

  • The datasource and delegate properties of the tableView are correctly bound to the TableViewController tableView的datasourcedelegate属性已正确绑定到TableViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM