【问题标题】:What can I do to access this Table View within a View Controller?如何在视图控制器中访问此表视图?
【发布时间】:2018-09-16 03:13:37
【问题描述】:

我已经查看了其他帖子,但我不确定接下来的步骤。这是我目前所拥有的。我需要在其他地方添加一个 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
    }
    /

}

然后我为我的连接设置了这个,但似乎无法让表格视图识别我尝试输出的任何数据。

我也有`class LookbookPostViewCell: UITableViewCell {

@IBOutlet weak var postLabel: UILabel!

} `

【问题讨论】:

    标签: ios swift uitableview tableview


    【解决方案1】:

    我可以通过改变来解决这个问题:

    类 LookbookPostViewController:UIViewController

    class LookbookPostViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
    

    然后右键单击并制作委托和数据源,即视图控制器,就像这张照片中的一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 2014-06-11
      • 1970-01-01
      相关资源
      最近更新 更多