对成员的不明确的引用'(_:numberOfRowsInSection:)'

时间:2016-05-25 03:37:12

标签: ios swift

我试图从Github中GET点击并在表格视图中弹出它们, 这里是整个代码,Gist是在其他地方定义的类:

var gists = [Gist]()

override func viewDidAppear(animated: Bool) {
    loadGists()
}

func loadGists() {
    GithubAPIManager.sharedInstance.fetchPublicGists() { result in
        guard result.error == nil else {
            print("Error 1")
            return
        }

        if let fetchedGists = result.value {
            self.gists = fetchedGists
        }
        self.tableView.reloadData()
        //Error here. 
    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return gists.count
}

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

    let gist = gists[indexPath.row]
    cell.textLabel?.text = gist.description
    cell.detailTextLabel?.text = gist.ownerLogin

    return cell
}

1 个答案:

答案 0 :(得分:1)

所以,问题是我没有将表视图的插座添加到View Controller.swift。 只需将表视图拖动到.swift文件即可创建它。