【发布时间】:2019-10-08 08:16:28
【问题描述】:
我的数组有问题,我正在使用返回不同 URL 的 WebService,我将此信息保存在数组中,然后将其显示在 UITableView 中,问题是在我的数组的第一个位置必须是一个链接,例如:www.sitioWeb.com,但是当我想在方法 didSelectedRowAt 中恢复它时,有时第一个位置是我数组的第二个
我已经查看了我的数组中包含的信息,一切看起来都很好,我从 WebService 恢复的信息恢复得很好并且没有问题
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayTituloN.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! InicioTableViewCell
cell.tituloN.text = arrayTituloN[indexPath.row]
cell.links.isHidden = true
//Limpiamos texto de la descripcion de la noticia
let descripcionI = arrayExcerptN[indexPath.row]
let betaDescripcion = descripcionI.replacingOccurrences(of: "<p>", with: "")
let alphaDescripcion = betaDescripcion.replacingOccurrences(of: "</p>", with: "")
let descripcion = alphaDescripcion.replacingOccurrences(of: " ", with: " ")
cell.descripcionN.text = descripcion
//Limpiamos el texto que tiene los links pdf
let linkI = arrayContentN[indexPath.row]
let betaLink = linkI.components(separatedBy: ".pdf")
let linkA: String = betaLink[0]
let linkX = linkA.components(separatedBy: "https:")
let linkS: String = linkX[1]
let linkUltra: String = "https:"+linkS+".pdf"
cell.contenidoN.text = linkUltra
cell.contenidoN.isHidden = true
print(cell.contenidoN.text!)
//Mostraremos imagenes dependiendo el link
if((cell.contenidoN.text?.contains(".pdf"))! && (cell.contenidoN.text?.contains(".png"))!){
cell.imagenN.image = UIImage(named: "ImagenLauncher")
}else if(cell.contenidoN.text?.contains(".pdf"))!{
cell.imagenN.image = UIImage(named: "documentosXSize")
}
contenido = cell.contenidoN.text!
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(contenido)
}
当我按下表格的第一个单元格时,您应该返回类似于以下内容的内容:“www.linkonthefirstcell.com” 问题是有时我会在第一个位置返回数组的第二个值。
我尝试通过以下方式将我的数组分配给变量“content”:var contenido: String = "" 当我使用数组中的 WebService 加载所有信息时,我会执行以下操作:
contenido= arraytitleN[indexPath.row]
但我有同样的错误
【问题讨论】:
标签: ios swift uitableview swift3 nsarray