加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 为什么tableview没有?

发布时间:2020-12-14 02:24:22 所属栏目:百科 来源:网络整理
导读:我有一个ViewController,其中有一个TableView.在我使用Alamofire请求获取数据后,我重新加载TableView的数据,因为tableView为零,所以它崩溃了. class TeamsVC: UIViewController,UITableViewDelegate,UITableViewDataSource{@IBOutlet var tableView: UITable
我有一个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
}
您将有三个选项可能会帮助您.

1 – 确保已将插座连接到工作台视图.

2 – 您可以将您的继承更改为如下所示

class TeamsVC: UITableViewController,UITableViewDataSource{
.
.
.
}

你将很容易访问

self.tableView.reloadData()

3-您可能必须以编程方式初始化它

第一

var tableView: UITableView  =   UITableView()

然后在viewdidload中

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读