【发布时间】:2018-05-06 17:16:42
【问题描述】:
我做了以下屏幕,它有 5 个部分;在前 4 部分中,我将使用一个数组来显示一些信息,最后一部分我将使用它来显示一个带有第二个数组的画廊。
通常在方法 numberOfRowsInSection 中,当我更改为 return self.obj_empresa?.count 时,我返回“return 5”并且我的屏幕显示像第一张图片一样0,仅显示第一部分,如第二张图像。我该如何解决这个问题:
我的代码:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//Muestra el # de celdas a mostrar
//return 5 before showed the 5 sections
return self.obj_empresa?.count ?? 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.infoEmpresaCell, for: indexPath) as! InfoEmpresaCell
cell.lbl_nombreEmpresa.text = self.obj_empresa?[indexPath.item].nombre_emp
cell.lbl_sloganEmpresa.text = "Subtitle"
cell.iv_perfilEmpresa.layer.cornerRadius = 10
cell.iv_perfilEmpresa.layer.masksToBounds = true
cell.selectionStyle = .none
return cell
}else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.redesSocialesEmpCell, for: indexPath) as! RedesSocialesEmpCell
cell.iv_facebook.isUserInteractionEnabled = true
let singletap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(visitar_facebook(singletap:)))
cell.iv_facebook.addGestureRecognizer(singletap)
cell.selectionStyle = .none
return cell
}else if indexPath.row == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.ubEmpCell, for: indexPath)
return cell
}else if indexPath.row == 3 {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.descEmpCell, for: indexPath) as! DescEmpCell
cell.lbl_descEmpresa.text = "Description"
cell.selectionStyle = .none
return cell
}else if indexPath.row == 4 {
let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.promoEmpCell, for: indexPath) as! PromoEmpCell
cell.selectionStyle = .none
return cell
}
return UITableViewCell()
}
当我在 numberOfRowsInSection 中返回 5 并设置此 cell.lbl_nombreEmpresa.text = self.obj_empresa?[indexPath.item].nombre_emp
I get this "error index out of range" in my cellForRowAt indexPath but if I return this self.obj_empresa?.count ?? 0 and I set thiscell.lbl_nombreEmpresa.text = self.obj_empresa?[indexPath.item].nombre_emp
我没有错误,但我的屏幕只显示第二张图片
第二张图片
提前致谢
【问题讨论】:
-
你说得对,我的朋友谢谢:D
-
太棒了!接受我的回答,干杯:)
标签: arrays swift uitableview swift3 swifty-json