uicollectionview:设置选定的特定项目数

时间:2014-11-01 11:21:47

标签: objective-c uicollectionview xcode6

工作很简单。
我在iOS中有一个 collectionview
我收到的项目数量将被选中。
我想表明这一点为ON。
应关闭休息。
禁用用户交互。

2 个答案:

答案 0 :(得分: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;
    }
}

答案 1 :(得分: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;

}