无法转换类型'() - >的值_'指定类型UIImageView

时间:2017-03-10 23:21:55

标签: ios swift uiimageview

我试图让UIImage视图可点击,但我没有运气。完成此任务的最佳方法是什么?我得到的错误是"无法转换类型'() - >的值_'指定类型' UIImageView'"。

lazy var profileImageView: UIImageView = {
     let imageView = UIImageView()
     imageView.image = UIImage(named: "ic_file_upload_white_48pt")
     imageView.translatesAutoresizingMaskIntoConstraints = false
     imageView.contentMode = .scaleAspectFill

     imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectorProfileImage)))
     imageView.isUserInteractionEnabled = true
     return imageView
 }

3 个答案:

答案 0 :(得分:40)

您告诉编译器您要使SQL> set serveroutput on SQL> declare 2 v_max_sal NUMBER(20) 3 begin 4 select max(sal) INTO v_max_sal 5 from emp e, dept d 6 where e.deptno=d.deptno 7 and d.dname='SALES'; 8 END; 9 / 包含闭包。如果你想让profileImageView包含那个闭包的结果,你需要在之后添加parens来调用闭包:

profileImageView

请注意关闭后的括号。这会在您第一次引用变量时将结果分配给变量lazy var profileImageView: UIImageView = { //your code here return imageView }()

答案 1 :(得分:5)

看起来像语法问题,请尝试

func profileImageView() -> UIImageView {
        let imageView = UIImageView()
        imageView.image = UIImage(named: "ic_file_upload_white_48pt")
        imageView.translatesAutoresizingMaskIntoConstraints = false
        imageView.contentMode = .scaleAspectFill

        imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectorProfileImage)))
        imageView.isUserInteractionEnabled = true
        return imageView
}

答案 2 :(得分:0)

您应该在计算属性的末尾添加圆括号以执行它。

lazy var profileImageView: UIImageView = {
     let imageView = UIImageView()
     imageView.image = UIImage(named: "ic_file_upload_white_48pt")
     imageView.translatesAutoresizingMaskIntoConstraints = false
     imageView.contentMode = .scaleAspectFill

     imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectorProfileImage)))
     imageView.isUserInteractionEnabled = true
     return imageView
 }()