iphone - iOS: indexPath.row, UICollectionView, and Images -
i trying display through uicollectionview 9 pictures in main iphone screen. have problem displaying. first picture repeated 2 times (in position 1 , position 2 of row 1).
something wrong in code ?
// define number of cell. - (nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section{ return 9; } // cell returned must retrieved call -dequeuereusablecellwithreuseidentifier:forindexpath: - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath{ static nsstring *idcell = @"cell"; sscollectionviewcell *cell = (sscollectionviewcell *) [collectionview dequeuereusablecellwithreuseidentifier: idcell forindexpath: indexpath]; int imagenumber = indexpath.row % 9; cell.imageview.image = [uiimage imagenamed: [nsstring stringwithformat:@"m2_img_%d@2x.png", imagenumber]]; return cell; }
don't need specify how many sections have in uicollectionview? have delegate method numberofitemsinsection, right? now, in numberofsectionsincollectionview delegate method, did specify 1? in:
- (nsinteger)numberofsectionsincollectionview: (uicollectionview *)collectionview { return 1; //if 9 images }
Comments
Post a Comment