0
votes

I have a custom UITableViewCell set up and it's not displaying any of the content. When the TableView was hooked up to the default cell it displayed the content. I have QuoteyTableViewCell set as the class for the cell in my storyboard. Not sure what I'm doing wrong, here's my code. Thanks :).

import UIKit

class KeepTableViewController: UITableViewController {

var keptQuotes : 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

    // 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

class 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 :)

1
Does your cell prototype in the storyboard has the class QuoteyTableViewCell assigned as well as the reuse identifier "Cell" ? - zisoft
@zisoft yeah, still doesn't work - mlevi
Is cellForRowAtIndexPath being called? Set a breakpoint there and step through the code - zisoft
@zisoft ok, I don't think is being called, put in some breakpoints and some print statements. Any idea why it wouldn't be called? Thanks :) - mlevi
I put that all together in an answer - zisoft

1 Answers

0
votes

Check these points:

  • The Content property of the TableView in the storyboard is set to "Dynamic Prototypes"

  • 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