pass qr image to another view controller
what are you doing:
let image: UIImage = UIImage() // <- its create image
let imageView: UIImageView = UIImageView() // its create some kind of container
imageView = image // ERROR!
you trying to set object with type UIImage to object with type UIImageView
correct:
let image: UIImage = UIImage()
let imageView: UIImageView = UIImageView()
imageView.image = image
How to transfer a photo from one viewcontroller to a UIImageView of another viewcontroller
Destination controller's view is not loaded in prepare(for:)
, It's not the best practice of passing data between controllers but you can make sure that view is loaded before touching any if it's subviews using outlets:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segue" {
if let detail = segue.destination as? DetailViewController {
detail.loadViewIfNeeded()
detail.PhotoProfile = selectedImage
}
}
}
How to pass an image from one viewcontroller to another viewcontroller in swift?
You're getting a crash here:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let productdetails = storyboard.instantiateViewController(withIdentifier: "LocatemypicViewController") as! LocatemypicViewController
print(imgobj.image)
productdetails.qrimgobj.image = imgobj.image
Specifically in this line: productdetails.qrimgobj.image = imgobj.image
... This is because you are trying to access or rather passing an object (UIImage
) to your qrimgobj
which I presume is a UIImageView
while that qrimgobj
property is not yet initialized. One of the things you can do is to have a property that holds the image temporarily and then pass it to qrimgobj
after the whole screen is loaded.
Example:
var qrimage: UIImage?
viewDidLoad() {
super.viewDidLoad()
self.qrimgobj.image = self.qrimage // Pass
}
Pass image from one view controller to another controller gives nil
You should use segue.destination
not create a new one , like this
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("In here")
if segue.identifier == "showImage" {
let next = segue.destination as! showImageController
next.newImage = UIImage(named: imageArray[0])
}
}
Related Topics
What's Nslocalizedstring Equivalent in Swift
Xcode Without Storyboard and Arc
How to Create a Round Cornered Uilabel on the Iphone
Get Last Image from Photos.App
React Native Responsive Font Size
What Is 'Vary for Traits' in Xcode 8
Tutorial for Slcomposeviewcontroller Sharing
Renew Push Certificate and Keep Current App Store App Working
Xcode 9 - "Fixed Width Constraints May Cause Clipping" and Other Localization Warnings
Dynamic Cell Width of Uicollectionview Depending on Label Width
How to Detect Network Signal Strength in iOS Reachability
How to Crop Uiimage on Oval Shape or Circle Shape
Swift 3 - How to Verify Class Type of Object
Creating a Shadow for a Uiimageview That Has Rounded Corners
Scroll Uitextfield Above Keyboard in a Uitableviewcell on a Regular Uiviewcontroller
Nsurlsession: How to Increase Time Out for Url Requests
Saving Image and Then Loading It in Swift (Ios)
Secitemadd and Secitemcopymatching Returns Error Code -34018 (Errsecmissingentitlement)