我希望在 uigesturerecognizer 的提示下点击我的表格 View 单元格内的图像时全屏显示。
问题是我的 didSelectRowAt 函数无法识别 postedimage
标识符。
Use of unresolved identifier 'postedImage'
我该如何解决这个问题?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FeedTableViewCell
imageFiles[indexPath.row].getDataInBackground { (data, error) in
if let imageData = data {
if let downloadedImage = UIImage(data: imageData) {
cell.postedImage.image = downloadedImage
}
}
}
cell.postedImage.image = UIImage(named: "test.png")
return cell
}
func removeImage() {
let imageView = (self.view.viewWithTag(100)! as! UIImageView)
imageView.removeFromSuperview()
}
func addImageViewWithImage(image: UIImage) {
let imageView = UIImageView(frame: self.view.frame)
imageView.contentMode = .scaleAspectFit
imageView.backgroundColor = UIColor.black
imageView.image! = image
imageView.tag = 100
let dismissTap = UITapGestureRecognizer(target: self, action: #selector(self.removeImage))
dismissTap.numberOfTapsRequired = 1
imageView.addGestureRecognizer(dismissTap)
self.view.addSubview(imageView)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.addImageViewWithImage(image: postedImage[indexPath.row])
}
最佳答案
I think you should first check and change the call in didSelect function from:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.addImageViewWithImage(image: postedImage[indexPath.row])
}
to
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! FeedTableViewCell
self.addImageViewWithImage(image: cell.postedImage.image)
}
现在,您的 addImageViewWithImage 将接受来自包含在单元格中的 ImageView 的图像。
关于ios - 点击 Swift 时全屏显示 tableviewcell 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45536405/