ios - UICollectionViewController reordering does not work when embedded in a container view -
reordering working in ios9 when add uicollectionviewcontroller
subclass
override func collectionview(collectionview: uicollectionview, moveitematindexpath sourceindexpath: nsindexpath, toindexpath destinationindexpath: nsindexpath)
it not work when uicollectionviewcontroller
subclass embedded in container view.
i've made demo of problem here
any ideas on why or how fix it?
the issue here put uicollectionview inside uicontainerview residing inside uiviewcontroller. requires few more steps uicollectionview work expected.
add following viewdidload in collectionviewcontroller:
self.collectionview!.addgesturerecognizer(uilongpressgesturerecognizer(target: self, action: "handlelonggesture:"))
then add following function collectionviewcontroller:
func handlelonggesture(gesture: uilongpressgesturerecognizer) { switch(gesture.state) { case uigesturerecognizerstate.began: guard let selectedindexpath = self.collectionview!.indexpathforitematpoint(gesture.locationinview(self.collectionview)) else { break } collectionview!.begininteractivemovementforitematindexpath(selectedindexpath) case uigesturerecognizerstate.changed: collectionview!.updateinteractivemovementtargetposition(gesture.locationinview(gesture.view!)) case uigesturerecognizerstate.ended: collectionview!.endinteractivemovement() default: collectionview!.cancelinteractivemovement() } }
finally make sure include following ensure handle datasource correctly:
override func collectionview(collectionview: uicollectionview, moveitematindexpath sourceindexpath: nsindexpath,toindexpath destinationindexpath: nsindexpath) { // swap values of source , destination }
check out link more on this.
hope helped out.
Comments
Post a Comment