ImageView重新调整nil

时间:2017-01-14 23:36:51

标签: ios swift null uiimageview

我有一个视图控制器CREATE TABLE Table1 ("id" int, "f_name" varchar2(9), "email" varchar2(21), "groupId" int) \\ INSERT ALL INTO Table1 ("id", "f_name", "email") VALUES (1, 'john', 'john123@hotmail.com') INTO Table1 ("id", "f_name", "email") VALUES (2, 'peter', 'peter456@gmail.com') INTO Table1 ("id", "f_name", "email") VALUES (3, 'johnny', 'john123@hotmail.com') INTO Table1 ("id", "f_name", "email") VALUES (4, 'peter8', 'peter456@gmail.com') SELECT * FROM dual \\ update table1 set "groupId" = (select min(t2."id") as groupId from table1 t2 where table1."email" = t2."email" group by t2."email" ) ,其中包含一个以“个人资料图片”为背景的按钮。当点击这个按钮时,我想将一个新的视图控制器OtherUserAccountViewController推到堆栈上,以简单地呈现这个所述概要图片的更大的ImageView。请注意,下面看到的屏幕截图的Storyboard标识符实际上是“imageTapped”,类是ImageTappedViewController

下面是我实例化和推送新视图控制器的功能:

在OtherUserAccountViewController.swift中:

ImageTappedViewController

ImageTappedViewController.swift:

@IBAction func profilePicButtonTapped() {

    let sb = UIStoryboard(name: "SuccessfulLogin", bundle: nil) //SB name: SuccessfulLogin

    let cc = (sb.instantiateViewController(withIdentifier: "imageTapped")) as!  ImageTappedViewController

    if cc.imageView == nil || cc.imageView == UIImage() {
        print("Nil") //<- Nil is printed upon firing this function
    } else {
        print("not nil")
    }

    //cc.imageView.image = self.profilePicButton.currentBackgroundImage <- breaks because the imageView is nil

    self.navigationController?.pushViewController(cc, animated: true)
}

我完全不知道为什么这个imageView会返回import UIKit class ImageTappedViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } }

我将imageView设置为默认显示可爱的Taylor Swift,如下所示;但无论如何,nil正在被退回。

ImageTappedViewController

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

首次初始化视图控制器时,将不会初始化IBOutlets。只有在viewDidLoad之后,他们的所有网点都将是非零的。将图像作为UIImage传递到viewDidLoad设置图像视图的图像属性中。