ios - cellForItemAtIndexPath is Changing Multiple Cells When Should Change One -
i may not understanding reusing of cells behaviour uicollectionview can tell me why 2 cells having properties changed in cellforitematindexpath when should 1 cell.
here's code.
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { photocollectionviewcell *cell = (photocollectionviewcell *) [collectionview dequeuereusablecellwithreuseidentifier:@"photocollectionviewcell" forindexpath:indexpath]; if (![[self.userphotos objectatindex:indexpath.row] isequaltostring:@""]){ nsstring *photourl = [self.userphotos objectatindex:indexpath.row]; nsurl *imageurl = [nsurl urlwithstring: photourl]; nsurlrequest *imagerequest = [nsurlrequest requestwithurl:imageurl]; [cell.photoimageview setimagewithurlrequest:imagerequest placeholderimage:[uiimage imagenamed:@"animage"] success:^(nsurlrequest *request, nshttpurlresponse *response, uiimage *image) { cell.photoimageview.image = image; cell.photoimageview.frame = cgrectmake(0, 0, 100.0f,100.0f); cell.photoimageview.contentmode = uiviewcontentmodescaleaspectfit; [cell.deleteimageview setframe:cgrectmake(-4.0f,-4.0f,28.0f,28.0f)]; cell.deleteimageview.layer.cornerradius = cell.deleteimageview.frame.size.width / 2; [cell.deleteimageview setalpha:0.8f]; cell.deleteimageview.layer.borderwidth = 1.0f; cell.deleteimageview.layer.bordercolor = [uicolor redcolor].cgcolor; } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error) { nslog(@"%@",[error localizeddescription]); }]; }else{ cell.photoimageview.image = [uiimage imagenamed:@"camera"]; cell.photoimageview.layer.borderwidth = 1.0f; cell.photoimageview.layer.bordercolor = [uicolor lightgraycolor].cgcolor; nslog(@"setting alpha & hiding delete"); cell.photoimageview.alpha = 0.4f; [cell.deleteimageview sethidden:yes]; }
the code in else part being executed on cells 2 , 6 example when should 6. although logging says it's executed on 6
any idea i'm going wrong?
thanks.
Comments
Post a Comment