I'm out of ideas and I have no idea how to solve this. Any help will be appreciated.
I've got the following situation:
- MainViewController which points to a CollectionView embedded in a NavController
- CollectionView points to a DetailViewController
- DetailViewController shows the full picture chosen in the CollectionView and has a button which passes this image to the MainViewController. Protocol and delegate are used for this
- This image should now be shown in an UIImageView in the MainViewController
The delegation works. I have an UIImage in my MainViewController. BUT: the UIImageView is nil. So when I set the chosen Image as the imageView.image it crashes. The MainViewController is initialized and I also see my default Picture. See below for the code, and the console-output.
MainViewController
class MainViewController: UIViewController, UserChosePhoto {
@IBOutlet var googleImageView: UIImageView!
var usedImage: UIImage? = nil
override func viewDidLoad() {
super.viewDidLoad()
/
println("viewDidLoad: \(googleImageView)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
func userHasChosen(image: UIImage) {
usedImage = image
googleImageView.image = usedImage
println("imageView: \(googleImageView)")
println("delegation: \(image)")
}
DetailViewController
protocol UserChosePhoto {
func userHasChosen(image: UIImage)
}
class GoogleDetailViewController: UIViewController {
@IBOutlet weak var bigImageView: UIImageView!
var image: UIImage? = nil
var delegate: UserChosePhoto? = nil
override func viewDidLoad() {
super.viewDidLoad()
/
bigImageView.image = image
let barButtonItem = UIBarButtonItem(title: "Use", style: UIBarButtonItemStyle.Plain, target: self, action: "tapped")
self.navigationItem.rightBarButtonItem = barButtonItem
self.delegate = MainViewController()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
func tapped() {
if (delegate != nil) {
self.delegate!.userHasChosen(bigImageView.image!)
}
self.dismissViewControllerAnimated(true, completion: nil)
}
}
Console Output: the first viewDidLoad-log comes from the app launch. found 10 pictures - a log from an API-call. imageView - this is the imageView in question. delegation: here i have an UIImage
viewDidLoad: <UIImageView: 0x7f863056f980; frame = (180 236; 240 128); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7f863056f710>> - (null)
found 10 pictures matching adam
imageView: nil
delegation: <UIImage: 0x7f86305ce6f0>, {300, 300}
Any tips would be cool - I'm really lost right now.
Thanks!