What can I do to access this Table View within a View Controller?

2615 views ios

I have checked out the other posts but I'm not sure next steps here. Here's what I have currently. Do I need to add a tableView variable somewhere else? Connect something differently?

class LookbookPostViewController: UIViewController {

    @IBOutlet weak var titleLabel: UILabel!
    override func viewDidLoad() {
        titleLabel.text = postArray[myIndex].title
        // Do any additional setup after loading the view.
        DispatchQueue.main.async {

    @IBOutlet weak var tableView: UITableView!

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
        return postArray.count

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "postViewCell", for: indexPath) as! LookbookPostViewCell

        cell.postLabel.text = postArray[indexPath.row].title
        return cell


I then have this set up for my connections, but can't seem to get the Table View to recognize any data I'm trying to output.enter image description here

I also have `class LookbookPostViewCell: UITableViewCell {

@IBOutlet weak var postLabel: UILabel!

} `

answered question

1 Answer


I was able to solve this by changing:

class LookbookPostViewController: UIViewController


class LookbookPostViewController: UIViewController, UITableViewDelegate, UITableViewDataSource

and then right clicking and making the delegate and datasource, the View Controller, like in this photo here.

enter image description here

posted this

Have an answer?


Please login first before posting an answer.