ios - Facing issue in UIScrollview in Swift -
ios - Facing issue in UIScrollview in Swift -
i new ios development.i working on swift programming.i trying create scrollview getting
"fatal error: unexpectedly found nil while unwrapping optional value"
every time. used optional value in below code.
here code
class viewcontroller: uiviewcontroller { var imagelist=["apple.jpeg","pears.jpeg","banana.jpeg","grapes.jpeg","mango.jpeg"] var itemnames = ["apple", "pear", "banana", "grapes", "mango"] var scrollview: uiscrollview! var ypos: float? ypos!=0 override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. createscrollview() } func createscrollview() { scrollview = uiscrollview(frame: view.bounds) var index = 0; index < self.imagelist.count; ++index { var fruitsimgview:uiimageview! fruitsimgview.frame=cgrectmake(0,cgfloat(ypos!), 320, 200) fruitsimgview.image=uiimage(named: self.imagelist[index]) scrollview.addsubview(fruitsimgview) ypos!=ypos!+200 } scrollview.contentsize = cgsizemake(scrollview.frame.size.width * cgfloat(imagelist.count), scrollview.frame.size.height) view.addsubview(scrollview) } }
i unable issue.please help me if 1 worked on it. in advance.
the sec line assignment nil variable.
var ypos: float? ypos!=0 // ypos nil!
replace with:
var ypos = 0 : float?
ios swift uiscrollview ios8
Comments
Post a Comment