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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -