Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义UITableViewCell为空(Swift)_Ios_Swift_Uitableview - Fatal编程技术网

Ios 自定义UITableViewCell为空(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

我正在尝试在Swift中设置自定义UITableViewCell。我还创建了XIB文件和swift文件。但是,当我运行应用程序时,这些单元格并没有填充我的自定义单元格,而是一个完全空白的单元格

我已将手机注册到:

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的类设置为自定义单元格类?是否添加了行中的节数?