ios - UICollectionview userinteraction disable of a first cell ,disables few other cells also on scroll -
hi want disable first cell of uicollectionview when in editing mode.i did following code in cellforrow
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { maincollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:reuseidentifier forindexpath:indexpath]; cell.curveimageview.image = nil; if(indexpath.item == 0){ [cell.curveimageview setimage:[uiimage imagenamed:@"addcell"]]; cell.subtitletext.text = @"new cell"; if(isediting){ [cell setuserinteractionenabled:no]; [cell setalpha:0.5]; } else{ [cell setuserinteractionenabled:yes]; [cell setalpha:1]; } } else{ [cell.curveimageview setimage:[uiimage imagenamed:@"flowerimage"]]; cell.subtitletext.text = [nsstring stringwithformat:@"%ld%@",(long)indexpath.row,@"hello looking ok"]; } [cell settag:indexpath.row]; return cell; }
at first time in editing mode ,i able user click on cells after scrolling ,few cells in first row disabled in random manner.could suggest me solution solve issue.
thank you
your problem is: first cell reuse after scrolling, , code doesn't change state, can solve this:
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { maincollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:reuseidentifier forindexpath:indexpath]; cell.curveimageview.image = nil; if(indexpath.item == 0){ [cell.curveimageview setimage:[uiimage imagenamed:@"addcell"]]; cell.subtitletext.text = @"new cell"; if(isediting){ [cell setuserinteractionenabled:no]; [cell setalpha:0.5]; } else{ [cell setuserinteractionenabled:yes]; [cell setalpha:1]; } } else{ [cell.curveimageview setimage:[uiimage imagenamed:@"flowerimage"]]; cell.subtitletext.text = [nsstring stringwithformat:@"%ld%@",(long)indexpath.row,@"hello looking ok"]; // add this: [cell setuserinteractionenabled:yes]; [cell setalpha:1]; } [cell settag:indexpath.row]; return cell; }
Comments
Post a Comment