答案 0 :(得分:1)
使用此代码将数据从tableview diselect传递到详细信息页面视图控制器,在该详细信息页面视图控制器中需要正确声明该变量。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cellData = newsDetails[indexPath.row] {
if let vc = YourDetail page ViewController as? DetailPageController {
vc.details = cellData
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
答案 1 :(得分:0)
解决了你的问题,
步骤:-在detailViewcontroller中,定义类似的变量
var getImage = UIImage()
var getTitle = String()
答案 2 :(得分:0)
据我所见, newDetails 是包含键和值的字典数组。您可以使用其键访问图像或词典中的任何内容。
if let image = newsDetails[indexPath.row]["yourImageKeyNameFromNewsDetails"] as? String {
Storyboard?.getImage = UIImage(named: image) ?? UIImage(named: "yourPlaceHolderImage")
}
我希望这能为您解释
答案 3 :(得分:0)
你好Madushan Senavirathna,
从您提供的图像中,我看到newsDetails是[Sting:Any]的数组,它将返回[String:Any]的对象。
但是您正在将对象分配给图像和从我从给定图像中观察到的字符串:
Storyboard?.getImage = newsDetails[indexPath.row]
Storyboard?.getTitle = newsDetails[indexPath.row]
我发现问题出在上述语法上。
从对象获取图像的理想语法如下:
if let imageString : String = newsDetails[indexPath.row]["imageKeyFromObject"]
{
Storyboard?.getImage = You need to handle image string as per your requirement (if local file name than handle it with UIImage(named: imageString) or if it is dynamic content from server then you have to handle it with url)
}