ios - ScrollView unable to display image which passed from another VC -
i need display image pass in viewcontroller
first,i have tested using imageview display image , works below:
thanks. appreciated.
class viewcontroller: uiviewcontroller, uiscrollviewdelegate { @iboutlet weak var tempimgview: uiimgeview! var passinimg: uiimage? override func viewdidload() { super.viewdidload() tempimgview.image = passinimg! }
when use uiscrollview ( scrolling large passinimg) , below code not working
probelm:
error : fatal error: unexpectedly found nil while unwrapping optional value
but have tested pass in image in above code.
what need done scrollview?
- should used in viewdidload?
class viewcontroller: uiviewcontroller, uiscrollviewdelegate { @iboutlet weak var myuiscrollview: uiscrollview! var myimgview: uiimageview! var passinimg: uiimage? override func viewdidload() { super.viewdidload() self.myuiscrollview.maximumzoomscale = 10.0 self.myuiscrollview.minimumzoomscale = 1.0 self.myuiscrollview.delegate = self myimgview.image = passinimg! self.myuiscrollview.addsubview(myimgview) } func viewforzoominginscrollview(scrollview: uiscrollview) -> uiview? { return myimgview }
first check if myuiscrollview connected outlet in storyboard , check before using optional variable:
if let img = passinimg { myimgview.image = img }
Comments
Post a Comment