表格视图即使在Xcode 10.1中自定义后仍显示基本

时间:2018-12-26 10:30:01

标签: swift xcode xcode10

我已经像以前的Xcode 8.1项目一样完成了所有工作... 但是,即使将其自定义,模拟器也会显示基本的空表行。 在viewdidload中尝试了一切,包括委托和数据源。

这是项目链接 https://drive.google.com/open?id=1hBR1cH5vr-sS4gLB-VBfF6iJPYKD59rd

(对不起,谷歌驱动器上传)

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var tblNames: UITableView!

var names = ["lonrvc","ktbfse","lnrset"]

override func viewDidLoad() {
    super.viewDidLoad()      
    self.tblNames.delegate = self
    self.tblNames.dataSource = self  
    self.tblNames.reloadData()   
}

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

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

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CustomTableViewCell        
    cell.lblName.text = names[indexPath.row]
    self.tblNames.reloadData()        
    return cell
      }
  }

我只想在自定义单元格上显示数组(而不是在基本单元格上)

1 个答案:

答案 0 :(得分:1)

看看您的项目,只需在情节提要中为标签设置一些约束,它就可以正常工作,哦,从self.tblNames.reloadData()删除行cellForRowAt

enter image description here