错误:在 swift 中使用 xib 文件注册自定义 tableView 单元格
Posted
技术标签:
【中文标题】错误:在 swift 中使用 xib 文件注册自定义 tableView 单元格【英文标题】:ERROR : registering a custom tableView cell in swift with an xib file 【发布时间】:2018-05-26 10:22:14 【问题描述】:我检查了所有标识符名称,还检查了其类的名称和所有内容。以下是我的代码和错误。
class StoreInfoViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
var store : StoreInfo = StoreInfo()
@IBOutlet weak var storeInfoTable: UITableView!
override func viewDidLoad()
super.viewDidLoad()
storeInfoTable.register(UINib(nibName: "CustomStoreInfoTableOneViewCell", bundle: nil), forCellWithReuseIdentifier: "storeinfocell1")
storeInfoTable.delegate = self
storeInfoTable.dataSource = self
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
return 1
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
let cell = storeInfoTable.dequeueReusableCell(withIdentifier: "storeinfocell1", for: indexPath) as! CustomStoreInfoTableOneViewCell
cell.storeInfoImage.sd_setImage(with: URL(string: (store.imageurl)), placeholderImage: UIImage(named: "r1"), options: [.continueInBackground, .progressiveDownload], completed: nil)
cell.storeinfoName.text = store.storename
Here's the error.
【问题讨论】:
Custom UITableViewCell from nib in Swift的可能重复 【参考方案1】:你写错了syntax
self. storeInfoTable.register(UINib(nibName: "CustomStoreInfoTableOneViewCell", bundle: nil), forCellReuseIdentifier: "storeinfocell1")
【讨论】:
【参考方案2】:您已在( :forCellWithReuseIdentifier)
注册您的笔尖,但您需要向( : forCellReuseIdentifier)
注册您的笔尖。请用这个更改您的注册行。
storeInfoTable.register(UINib(nibName: "CustomStoreInfoTableOneViewCell", bundle: nil), forCellReuseIdentifier: "storeinfocell1")
【讨论】:
你能解释一下吗? (:forCellWithReuseIdentifier) 用于注册collection view cell以上是关于错误:在 swift 中使用 xib 文件注册自定义 tableView 单元格的主要内容,如果未能解决你的问题,请参考以下文章