如何在视图控制器中访问此表视图?

时间:2018-09-16 03:13:37

标签: ios swift uitableview tableview

我已经查看了其他帖子,但不确定此处的下一步。这是我目前所拥有的。我是否需要在其他地方添加tableView变量?连接不同的东西吗?

class LookbookPostViewController: UIViewController {

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

    @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
        print(postArray)
        return cell
    }
    /

}

然后我为连接建立了此设置,但似乎无法使“表视图”识别我要输出的任何数据。enter image description here

我也有`LookbookPostViewCell类:UITableViewCell {

@IBOutlet weak var postLabel: UILabel!

} `

1 个答案:

答案 0 :(得分:0)

我能够通过以下方法解决此问题:

LookbookPostViewController类:UIViewController

class LookbookPostViewController: UIViewController, UITableViewDelegate, UITableViewDataSource

然后右键单击并创建委托和数据源,即View Controller,如此处的这张照片。

enter image description here

相关问题