Why is there no table?

I have a ViewController, and inside that I have a TableView. After I get the data using the Alamofire query, I reload the TableView data and where it falls, because the tableView is zero.

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
}
+4
source share
1 answer

You will have three options that can help you.

1 - Make sure you plug the power outlet into the view on the table.

2 - you can change your inheritance as below

class TeamsVC: UITableViewController, UITableViewDelegate, UITableViewDataSource{
.
.
.
}

you will have easy access to

self.tableView.reloadData()

3 You may need to initialize it programmatically

the first

var tableView: UITableView  =   UITableView()

and then in viewdidload

tableView = UITableView(frame: UIScreen.mainScreen().bounds, style: UITableViewStyle.Plain)
tableView.delegate      =   self
tableView.dataSource    =   self
+3
source

Source: https://habr.com/ru/post/1673393/


All Articles