填充TableView Swift

时间:2016-06-22 02:17:38

标签: ios iphone swift uitableview

Swift的新手,四处寻找并学习。我似乎无法在我的TableView中加载任何东西:/我已经跟随了几个不同的演练(包括Apple的)并且拖着SO寻找解决方案,但我必须忽略一些东西..

我原本试图从plist中提取数据,然后我放弃并尝试使用数组,然后我放弃并尝试硬编码字符串,没有!

  • 我首先尝试使用默认的单元格类
  • 我已经更新了控制器的自定义类和我制作的单元类。
  • 我尝试在viewDidLoad()
  • 中添加delegate / datasource = self
  • 在viewDidLoad()函数中没有出现断点,这对我来说似乎很奇怪。

TIA

class MessagesViewController: UITableViewController {

    let CellIdentifier = "MatchTableViewCell"

    var matches = [String]()
    var test = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()

        test = ["Pizza", "bungholio", "Metallica"]
        tableView.delegate = self
        tableView.dataSource = self

        tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: CellIdentifier)

        let filePath = NSBundle.mainBundle().pathForResource("Books", ofType: "plist")

        let dict = NSDictionary(contentsOfFile: filePath!)
        matches = dict!.objectForKey("Matches") as! [String]


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3 //test.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        // Dequeue Resuable Cell
        let cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath) as! MatchTableViewCell

        cell.nameLabel.text = "test" //test[indexPath.row]

        return cell
    }

编辑:在此链接后启动了一个新项目,在成功完成一个

之后仍然不知道出了什么问题

https://www.ralfebert.de/tutorials/ios-swift-uitableviewcontroller/

0 个答案:

没有答案
相关问题