ios - Unrecognized selector sent to instance with Swift -
i'm trying make slideshow app swift have problem, in main.storyboard add 1 imageview , 1 button, when user click on button slideshow animate.
i wrote code @ viewcontroller.swift
@iboutlet var imageview: uiimageview! @iboutlet var animatebtn: uibutton! @ibaction func animatebtnclicked(sender: uibutton) { startanimation() } var imagelist:[uiimage]=[] override func viewdidload() { super.viewdidload() in 1 ... 3{ let imagename="\(i).jpg" imagelist.append(uiimage(named: imagename)!) } } func startanimation()->(){ if !imageview.isanimating() { imageview.animationimages=[imagelist] imageview.startanimating() animatebtn.settitle("stop animation", forstate:uicontrolstate.normal)} else { imageview.stopanimating() } } at appdelegate.swift didn't write code.
but app crashed when clicked button , show message error
2014-12-02 09:54:55.693 #4 animation photo[921:613] -[swift._nsswiftarrayimpl _isresizable]: unrecognized selector sent instance 0x7f82126615d0 2014-12-02 09:54:55.698 #4 animation photo[921:613] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[swift._nsswiftarrayimpl _isresizable]: unrecognized selector sent instance 0x7f82126615d0'
uiimageview's animationimages property should array of uiimage objects. you're setting array of array of uiimage objects. that's because you've got array:
var imagelist:[uiimage]=[] ...but when set property, wrap in square brackets, puts existing array another, further array:
imageview.animationimages=[imagelist] when imageview starts trying animate images, expects each element in array uiimage, instead finds array. tries invoke uiimage selector, _isresizable, on array object, , that's error you're seeing:
-[swift._nsswiftarrayimpl _isresizable]: unrecognized selector sent instance 0x7f82126615d0 so, don't wrap array array. set directly property:
imageview.animationimages = imagelist
Comments
Post a Comment