2014-11-01 75 views

回答

0
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    loyalityCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 


    NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults]; 
    NSString *userStamps = [userDefault objectForKey:@"stamps"]; 


    for (int i=0; i<=userStamps.intValue; i++) 
    { 
     if (indexPath.row < userStamps.integerValue) 
     { 
      cell.stampImage.image = [UIImage imageNamed:@"stamphover.png"]; 
      cell.selected= true; 
      cell.userInteractionEnabled= NO; 

     } 
     else 
     { 
      cell.stampImage.image= [UIImage imageNamed:@"stamp.png"]; 
      cell.selected = true; 
      cell.userInteractionEnabled= NO; 

     } 
    }   
return cell; 

} 
0

你可以在下面的方法中設置它,但你必須設置正確的代碼。

-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
//stuff 
if(indexPath.row %2 ==0) //replace this with your condtion. 
    { 
     cell.selected = YES; 
     cell.userInteractionEnabled = YES; 
    } 
    else 
    { 
     cell.selected = NO; 
     cell.userInteractionEnabled = NO; 
    } 
} 
+0

感謝@Sunny,我已經更新了我的病情。它現在工作正常 – magid 2014-11-02 11:13:35