Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView重新排序和更改所选项目_Ios_Objective C_Uicollectionview_Reuseidentifier - Fatal编程技术网

Ios UICollectionView重新排序和更改所选项目

Ios UICollectionView重新排序和更改所选项目,ios,objective-c,uicollectionview,reuseidentifier,Ios,Objective C,Uicollectionview,Reuseidentifier,我目前面临一个问题,当我的collectionView项目滚动出屏幕并切换所选单元格时,它们会更改项目的顺序。此时,它们被组织起来,以便垂直滚动(有两个项目并排): 这是我的-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath方法: - (UICollectionViewCell *)collectionVie

我目前面临一个问题,当我的
collectionView
项目滚动出屏幕并切换所选单元格时,它们会更改项目的顺序。此时,它们被组织起来,以便垂直滚动(有两个项目并排):

这是我的
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath方法:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *identifier = @"FriendCell";
    FriendsCell *cell = (FriendsCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    //Friend Object
    PFUser *friend = [self.friendsArray objectAtIndex:indexPath.item];
    cell.friendId = currentFriend.objectId;

    //Setup Cell
    if (!cell.isSelected) {
        cell.layer.backgroundColor = [UIColor whiteColor].CGColor;
    } else {
        cell.layer.backgroundColor = FlatGreen.CGColor;
    }

    //Set Profile Image
    if (!cell.profileImageView) {
        cell.profileImageView = [UIImageView new];
        cell.profileImageView.image = [UIImage imageNamed:@"ProfileImagePlaceholder"];
        [cell addSubview:cell.profileImageView];
    }

    //Set Username
    if (!cell.usernameLabel) {
        //Set Username Label
        cell.usernameLabel = [UILabel new];
        cell.usernameLabel.text = friend[@"username"];
        cell.usernameLabel.textColor = [UIColor lightGrayColor];
        [cell addSubview:cell.usernameLabel];

    } else {
        if (cell.isSelected) {
            cell.usernameLabel.textColor = [UIColor whiteColor];
        } else {
            cell.usernameLabel.textColor = [UIColor lightGrayColor];
        }
    }

    return cell;
}
didSelectItemAtIndexPath:
diddescitematindexpath:
如果有人能发现这一切发生的原因,我将不胜感激

试试看

dequeueReusableCellWithReuseIdentifier:nil

reuseIdentifier
是非空参数。这将崩溃。您可以给dequeueReusableCellWithReuseIdentifier:@“好的,现在我明白了。但我在tableView中使用了这个概念。这应该如何解决问题?我在tableView中使用了这个概念。其中,我在CellForRowatineXpath方法中自定义了单元格。所以我给了零分。集合视图我没有尝试。
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {

    //Determine the selected friend by using the indexPath
    PFUser *deselectedFriend = [self.friendsArray objectAtIndex:indexPath.item];

    //Remove the deselected friend's objectId from our array
    [self.friendsToAdd removeObject:deselectedFriend.objectId];

    //Show Deselected View
    FriendsCell *currentCell = (FriendsCell *)[collectionView cellForItemAtIndexPath:indexPath];

    //Animate
    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{

        //Update Card
        currentCell.layer.backgroundColor = [UIColor whiteColor].CGColor;
        currentCell.profileImageView.alpha = 1.0;
        currentCell.usernameLabel.textColor = [UIColor lightGrayColor];

    } completion:nil];
}
dequeueReusableCellWithReuseIdentifier:nil