Ios 自定义UITableViewCell为空(Swift)
我正在尝试在Swift中设置自定义UITableViewCell。我还创建了XIB文件和swift文件。但是,当我运行应用程序时,这些单元格并没有填充我的自定义单元格,而是一个完全空白的单元格 我已将手机注册到:Ios 自定义UITableViewCell为空(Swift),ios,swift,uitableview,Ios,Swift,Uitableview,我正在尝试在Swift中设置自定义UITableViewCell。我还创建了XIB文件和swift文件。但是,当我运行应用程序时,这些单元格并没有填充我的自定义单元格,而是一个完全空白的单元格 我已将手机注册到: self.myTableView.registerClass(customCell.self, forCellReuseIdentifier: "cell") func tableView(tableView: UITableView, numberOfRowsInSection s
self.myTableView.registerClass(customCell.self, forCellReuseIdentifier: "cell")
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = myTableView.dequeueReusableCellWithIdentifier("cell") as! customCell
cell.descriptionLabel.text = "test"
return cell
}
我还设置了以下内容:
self.myTableView.registerClass(customCell.self, forCellReuseIdentifier: "cell")
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = myTableView.dequeueReusableCellWithIdentifier("cell") as! customCell
cell.descriptionLabel.text = "test"
return cell
}
此外,我在自定义单元格中设置了指向UILabel的链接。当我尝试更新它时,应用程序崩溃。该行为如上所示的cell.descriptionLabel.text=“test”。您必须注册nib,而不是注册
UITableViewCell
类,例如:
self.tableView.registerNib(UINib(nibName: "CustomTableViewCell", bundle: nil),
forCellReuseIdentifier: "cell")
nibName
是XIB文件的名称,但没有扩展名.XIB
。您是否在identity inspector下将XIB的类设置为自定义单元格类?是否添加了行中的节数?