我有一个数组的问题,我正在使用一个返回不同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= arraytitleNindexPath.row
但我也犯了同样的错误
发布于 2019-05-22 05:47:08
单击顶部单元格时,需要打印第一个值,如下所示
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(arraytitleN[indexPath.row])
}
在此处赋值
contenido = cell.contenidoN.text!
不能保证它是索引=0的值,因为所有可见单元格都调用了cellForRowAt
,因此可以将它赋给任何其他行中的任何值
https://stackoverflow.com/questions/56246702
复制相似问题