我有一个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)