问题描述
学习Swift和Storyboard,我试图创建一个重复单元格视图(UITableView)。
到目前为止,我已经创建了一个带有UIView的视图,该视图链接到内部带有UITableViewCell的UITableView。我遇到的问题是我的单元格未按如下所示显示“ woof”。
我的View Controller看起来像这样:
import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId") as! MyListViewCell
cell.myLabel.text = "woof"
return cell
}
}
经过研究,我认为我不需要注册:
myTableView.register(UITableViewCell.self,forCellReuseIdentifier: "cellId")
因为它已经成功链接为出口
但是我想我可能需要像这样做委托和数据源:
myTableView.datasource = self
myTableView.delegate = self
但是我收到了:Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
我正在尝试使用我想 仅打算使用一个ViewController的MVVM。我是否打算改用UITableViewController?
我已验证在情节提要中正确设置了单元格标识符。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)