I am building an app that lets the user create a "Story" which consists of a title and a text.
I am implementing a tableView that shows all created stories. So far everything works. But here is my issue:
When the user enters a title or text that is longer that what tableViewCell would be able to display, that cell doesn't show up at all. Others with shorter names still do though.
I am using the cell style "subtitle".
How does one go about limiting the amount of text showing in the cell and what causes this bug? Because even if I find a way to fix it, there will probably still be a problem with text running off the screen.
Here is the code in my UITableViewController
class:
class StoryTableViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return savedStories.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
cell.textLabel?.text = savedStories[indexPath.row].title
cell.detailTextLabel?.text = savedStories[indexPath.row].text
return cell
}
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.
}
Here is a screenshot of the UI from the interface builder: