MNM MNM - 5 months ago 27
iOS Question

No information is showing in my tableview inside a viewController

I have set up my table view to be filled form two arrays. I did this successfully when it was just in a tableview but not that I put it in a view controller none of the information is being displayed. I don't know what I did wrong I set up the viewController just like I did with the tableviewcontroller.
What should happen is that a row will be created and filled in with the information and continue this until all the data has been filled in.
The problem is that none of the data is showing up. I don't know what I am missing here. Any help would be appreciated.

Here is what I have;

class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


var titleDate = ["Apple", "Apricot", "Banana", "Kiwi" , "Juniperberry" , "GhostBusteres"]
var descriptionDate = ["One", "Two", "Three", "4", "5", "6"]

@IBOutlet weak var myTableView: UITableView!
// MARK: - UIViewController lifecycle

override func viewDidLoad() {
super.viewDidLoad()
myTableView.editing = true
}

// MARK: - UITableViewDataSource

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleDate.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Coupon", forIndexPath: indexPath) as! CouponTableViewCell


cell.couponTitle.text = titleDate[indexPath.row]
cell.couponDescription.text = descriptionDate[indexPath.row]
cell.couponAnother.text = "Like a bloody storm"

return cell
}

func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return .None
}

func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}

func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let movedObject = self.titleDate[sourceIndexPath.row]
titleDate.removeAtIndex(sourceIndexPath.row)
titleDate.insert(movedObject, atIndex: destinationIndexPath.row)
descriptionDate.removeAtIndex(sourceIndexPath.row)
descriptionDate.insert(movedObject, atIndex: destinationIndexPath.row)
NSLog("%@", "\(sourceIndexPath.row) => \(destinationIndexPath.row) \(titleDate)")
// To check for correctness enable: self.tableView.reloadData()

}


}

And I also have the cell class that links the labels to the variables and that also works.

Thank you for any help with this.

Answer

You need to set the UITableView dataSource and delegate.
When you were using the UITableViewController, the dataSource and delegate were already set.
See UITableView - Managing the Delegate and the Data Source documentation.