Closed. This question needs to be more focused。它目前不接受答案。
想改进这个问题吗?更新问题,使其只关注一个问题editing this post
三年前关闭。
如何在UIViewController中填充UITableView?
UITableView是动态的,使用原型单元。
(使用Swift)
This is what I have

最佳答案

执行以下操作:

import UIKit

class tableViewOne: UIViewController{

    @IBOutlet var tableView: UITableView!
    // your data
    var dummyData = ["data 0","data 1","data 2"]

    override func viewDidLoad() {
        super.viewDidLoad()

    }

}

extension tableViewOne: UITableViewDataSource, UITableViewDelegate {
    // Define no of rows in your tableView
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dummyData.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        // Default cell
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell")! as UITableViewCell

        cell.textLabel!.text = dummyData[indexPath.row]

        return cell;
    }

}

注意:不要忘记在DataSource中设置DelegateUITableViewstoryboard。如果已在storyboard中定义,则无需以编程方式定义。

关于ios - 将数据/行添加到ViewController中的UITableView。 swift ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38815390/

10-14 23:30