小编Adr*_* I.的帖子

为什么tableview没有?

我有一个ViewController,其中有一个TableView.在我使用Alamofire请求获取数据后,我重新加载TableView的数据,因为tableView为零,所以它崩溃了.

class TeamsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{

@IBOutlet var tableView: UITableView!

var terminArr = [Termin]()
override func viewDidLoad() {        
    TerminResource.getTerminsByUsername(username: "SonnyBlackzz"){
        response in

        self.terminArr = response
        self.tableView.reloadData()
    }
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.terminArr.count;
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

    print(self.terminArr[indexPath.row].name)

    cell.textLabel?.text = self.terminArr[indexPath.row].name

    return cell
}
Run Code Online (Sandbox Code Playgroud)

uitableview uiviewcontroller swift

5
推荐指数
1
解决办法
3205
查看次数

标签 统计

swift ×1

uitableview ×1

uiviewcontroller ×1