ios - Perform action on selection of UICollectionViewCell? -
i call function when cell pressed , able change function based on cell pressed. here code currently:
override func numberofsectionsincollectionview(collectionview: uicollectionview) -> int { //#warning incomplete method implementation -- return number of sections return 4 } override func collectionview(collectionview: uicollectionview, numberofitemsinsection section: int) -> int { //#warning incomplete method implementation -- return number of items in section return 10 } override func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { let cell = collectionview.dequeuereusablecellwithreuseidentifier(reuseidentifier, forindexpath: indexpath) as! uicollectionviewcell // configure cell return cell } func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize { return cgsizemake(90, 90) } func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, insetforsectionatindex section: int) -> uiedgeinsets { return uiedgeinsetsmake(10, 10, 10, 10) } func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, minimumlinespacingforsectionatindex section: int) -> cgfloat { return 10 } // mark: uicollectionviewdelegate // uncomment method specify if specified item should highlighted during tracking override func collectionview(collectionview: uicollectionview, shouldhighlightitematindexpath indexpath: nsindexpath) -> bool { return true } // uncomment method specify if specified item should selected override func collectionview(collectionview: uicollectionview, shouldselectitematindexpath indexpath: nsindexpath) -> bool { return true } // uncomment these methods specify if action menu should displayed specified item, , react actions performed on item override func collectionview(collectionview: uicollectionview, shouldshowmenuforitematindexpath indexpath: nsindexpath) -> bool { return true } override func collectionview(collectionview: uicollectionview, canperformaction action: selector, foritematindexpath indexpath: nsindexpath, withsender sender: anyobject?) -> bool { return true } override func collectionview(collectionview: uicollectionview, performaction action: selector, foritematindexpath indexpath: nsindexpath, withsender sender: anyobject?) { self.printthatitworked() } func printthatitworked() { println("it worked") }
the function printthatitworked()
should called whenever cell selected, , able have print cell number x pressed. how go doing this?
the delegate method didselectcell...
want put code.
override func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath) { // can use indexpath "cell number x", or cell like: let cell = collectionview.cellforitematindexpath(indexpath) printthatitworked() }
Comments
Post a Comment