将图像导入到特定tableview单元格中的imageview

问题描述

我想要我的快速代码从手机上的相册导入照片。每个单独的单元格中都有一个按钮,按钮的目标是导入照片并将其放置在单独的单元格图像中,在本例中为imageview pic。白色的导入按钮应从照片库中拍摄照片并将其放置在粉红色的imageview上。 那是我尝试将图像选择器与imageview图片连接的地方。所有导入的照片代码都在customtv类中。在takePhoto func中以及在用户放置图像的位置,我的代码中出现2个错误。我需要消除错误的帮助。

enter image description here

import UIKit

 class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{
var tableView = UITableView()
var arr = [4]

func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
    return cell
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    view.addSubview(tableView)
    
    let VCframe = view.frame
    
    let height = VCframe.height * 0.8
    let widthx = VCframe.width
    
    
    tableView.frame = CGRect(x: 10,y: 0,width: widthx - 20,height: height)
    
    tableView.delegate = self
    tableView.dataSource = self
    view.addSubview(tableView)
    
    
    
    tableView.register(customtv.self,forCellReuseIdentifier: "cell")
    
}
class customtv: UITableViewCell,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
    
    var imagePicker: UIImagePickerController!

    
    @objc func importPhoto() {
        imagePicker =  UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = .photoLibrary
        present(imagePicker,animated: true,completion: nil)
        
        
        
        
    }
    
    
    
    func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        
        // The info dictionary may contain multiple representations of the image. You want to use the original.
        guard let selectedImage = info[.originalImage] as? UIImage else {
            fatalError("Expected a dictionary containing an image,but was provided the following: \(info)")
        }
        
        // Set photoImageView to display the selected image.
        
        pic.image = selectedImage
        
        // Dismiss the picker.
        dismiss(animated: true,completion: nil)
    }
    
    
    
    
    lazy var backView : UIView = {
        let view = UIView(frame: CGRect(x: 10,y: 6,width: self.frame.width,height: 110))
        view.backgroundColor = .green
        print(self.frame.width)
        return view
    }()
    
    
    
    override func layoutSubviews() {
        backView.clipsToBounds = true
        backView.frame =  CGRect(x: 0,width: bounds.maxX,height: 110)
        
        
    }
    
    lazy var btn : UIButton = {
        let press = UIButton(frame: CGRect(x: 140,y: 3,width: 120,height: 50))
        press.backgroundColor = .white
        press.addTarget(self,action: #selector(importPhoto),for: .touchDown)
        
        return press
    }()
    
    lazy var pic : UIImageView = {
        let press = UIImageView(frame: CGRect(x: 0,y: 40,height: 50))
        press.backgroundColor = .magenta
        
        
        return press
    }()
    
    override func setSelected(_ selected: Bool,animated: Bool) {
        super.setSelected(animated,animated: true)
        addSubview(backView)
        
        backView.addSubview(pic)
        backView.addSubview(btn)
    }
    
    
    
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...