gpt4 book ai didi

swift - 即使在 Xcode 10.1 中自定义后, TableView 仍然显示基本

转载 作者:行者123 更新时间:2023-11-28 13:55:33 24 4
gpt4 key购买 nike

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

这是项目链接 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
}
}

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

最佳答案

看看你的项目,只需在 Storyboard中为你的标签设置一些约束,它应该可以正常工作,哦,从 cellForRowAt 中删除行 self.tblNames.reloadData()

enter image description here

关于swift - 即使在 Xcode 10.1 中自定义后, TableView 仍然显示基本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53930776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com