【发布时间】:2017-01-05 07:15:45
【问题描述】:
假设我收到了这样的 JSON 响应:
{
"product_list" = (
{
"product_id" = 33;
"product_image" = (
);
"product_sku" = asdasd;
"product_title" = "Product 1";
},
{
"product_id" = 58;
"product_image" = (
);
"product_sku" = kkkk222;
"product_title" = p1;
},
{
"product_id" = 119;
"product_image" = (
);
"product_sku" = 123456;
"product_title" = product;
},
{
"product_id" = 120;
"product_image" = (
);
"product_sku" = 456789;
"product_title" = "product 3";
}
);
"xxx_api" = "product_information";
}
这就是我使用 cellForRowAt indexPath 填充表格的 Cell 的方式。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: SpecificCatagoryBodyCell = tableView.dequeueReusableCell(withIdentifier: "SpecificCatagoryBodyCell") as! SpecificCatagoryBodyCell
let categoryList = sCategory[indexPath.row]
cell.product_id.text = String(categoryList.product_id)
cell.sCategoryName.text = categoryList.product_title
let profileImage = categoryList.product_image
SDWebImageManager.shared().downloadImage(with: profileImage, options: [], progress: nil) { downloadedImage, error, cacheType, isDownloaded, url in
cell.sCategoryImage.image = downloadedImage
}
return cell
}
如果我想填充 tableView 的 Cell ,一切都很好。问题是有时我需要使用不同的数据来拨打任何电话,假设这里我需要来自 JSON 响应的 product_id 并使用相应的号码拨打电话。如何提取 tableView 索引之外的数字,可以将其提取到函数中,将其存储在变量中并使用它。这是我提供的视觉效果,以便更好地理解。在第一张图片中,您可以看到表格中有 Cell
当我点击 Cell 时,它会转到不同的 ViewController ,所以我希望当我点击 Cell 时它会通过 product_id 并使用该 product_id 进行另一个 post 调用以显示产品的详细信息。这是下面的产品详细信息页面。
希望这是有道理的。如果您需要,我很乐意提供更多详细信息。非常感谢。
【问题讨论】:
标签: swift