Objective c uicollectionview:设置选定的项目的特定数量

Objective c uicollectionview:设置选定的项目的特定数量,objective-c,uicollectionview,xcode6,Objective C,Uicollectionview,Xcode6,工作很简单。我在iOS中有一个collectionview。我收到了要选择的项目数。我想将其显示为打开。应关闭Rest。用户交互被禁用。您可以在下面的方法中进行设置,但必须设置正确的代码 -(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ //stuff if(indexPath.row %2 ==0)

工作很简单。
我在iOS中有一个collectionview
我收到了要选择的项目数。
我想将其显示为打开。
应关闭Rest。
用户交互被禁用。

您可以在下面的方法中进行设置,但必须设置正确的代码

-(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;
    }
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath
{
忠诚cell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:@“cell”forIndexPath:indexPath];
NSUserDefaults*userDefault=[NSUserDefaults standardUserDefaults];
NSString*userStamps=[userDefault objectForKey:@“stamps”];

对于(inti=0;ithanks@Sunny),我已经更新了我的状态。现在工作正常
-(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;

}