ios - UILabel In UICollectionViewCell is setting after scrolling? -
in code,i trying use uiimage
& uiabel
in uicollectionviewcell
.what doing if there no image in uicollectionviewcell
want shift uilabel
upwards.so used 2 frames of label , checked if(uiimageview.image==nil)
showing effect after scrolling? do? here code did-
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { uicollectionviewcell *mycell=(uicollectionviewcell*)[self.view viewwithtag:1]; mycell = [collectionview dequeuereusablecellwithreuseidentifier:@"cell" forindexpath:indexpath]; uilabel *label=(uilabel*)[mycell viewwithtag:12]; uiimageview *collectionviewimage=(uiimageview*)[mycell viewwithtag:11]; nsstring *collectionviewimagename=[imagescollectionviewarray objectatindex:indexpath.row]; collectionviewimage.image=[uiimage imagenamed:collectionviewimagename]; if (collectionviewimage.image==nil) { [collectionviewimage setbackgroundcolor:[uicolor clearcolor]]; [label setframe:cgrectmake(35, 73, 309, 54)]; label.text=[lablecolectionviewarray objectatindex:indexpath.row]; return mycell; }else { [label setframe:cgrectmake(20, 294, 352, 49)]; label.text=[lablecolectionviewarray objectatindex:indexpath.row]; return mycell; } }
try remove cell contentview subviews every collectionview
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath
method call.
use
for([uiview *view in cell.contentview.subviews]){ [view removefromsuperview]; view=nil; }
and replace line of code uicollectionviewcell mycell=(uicollectionviewcell)[self.view viewwithtag:1];
with
uicollectionviewcell *mycell=nil;
Comments
Post a Comment