我有JSON图片。
let imagestring : String? = (myData as AnyObject).value(forKey: "Post_mid_image") as? String
if imagestring != nil{
let imageTrueString = "https://www.zdoof.com/" + imagestring!
self.imageStringArray.append(imageTrueString )
print(self.imageStringArray)
}
当我试图把它放在桌面视图上时:
let myImage = cell.viewWithTag(30) as! UIImageView
let myImageString : String? = imageStringArray[indexPath.row]
if myImageString != nil{
let ImageUrl = URL.init(string: myImageString!)
myImage.kf.setImage(with: ImageUrl)
}
显示如下错误:
致命错误:索引超出范围
我的代码出了什么问题?
答案 0 :(得分:0)
这样的行数方法
Column1 Column2
Test Test 12212
Test Test 6588476
Something Something 4125
What What is this 1254
使用如果让来避免强行投射
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imageStringArray.count
}
<强>更新: - 强>
if let myImage = cell.viewWithTag(30) as? UIImageView {
if let myImageString = imageStringArray[indexPath.row] as? String {
let ImageUrl = URL.init(string: myImageString!)
myImage.kf.setImage(with: ImageUrl)
}
}