Objective c 是否可以在2`UICollectionView之间移动对象`

Objective c 是否可以在2`UICollectionView之间移动对象`,objective-c,uicollectionview,Objective C,Uicollectionview,我正在使用UICollectionView,我有两个收藏。我需要通过拖动将对象从第一个移动到第二个。 我的项目是基于 是否可以通过拖动在2UICollectionView之间移动对象?是!(附带警告) 您需要替换委托方法willMoveToIndexPath并进行一些修改: - (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtI

我正在使用
UICollectionView
,我有两个收藏。我需要通过拖动将对象从第一个移动到第二个。 我的项目是基于

是否可以通过拖动在2
UICollectionView
之间移动对象?

是!(附带警告)

您需要替换委托方法willMoveToIndexPath并进行一些修改:

 - (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtIndexPath:(NSIndexPath *)theFromIndexPath willMoveToIndexPath:(NSIndexPath *)theToIndexPath
{

/*  code removed from example code
id theFromItem = [self.deck objectAtIndex:theFromIndexPath.item];
[self.deck removeObjectAtIndex:theFromIndexPath.item];
[self.deck insertObject:theFromItem atIndex:theToIndexPath.item];
 */

NSLog(@"From: %d %d    To: %d %d", theFromIndexPath.section, theFromIndexPath.row, theToIndexPath.section, theToIndexPath.row);

    NSMutableArray *fromSectionArray = mySectionArray[theFromIndexPath.section];
NSMutableArray *toSectionArray = mySectionArray[theToIndexPath.section];
id theFromItem = fromSectionArray.myItemArray[theFromIndexPath.item];
[fromSectionArray.myItemsArray removeObjectAtIndex:theFromIndexPath.item];
[toSectionArray.myItemsArray insertObject:theFromItem atIndex:theToIndexPath.item];
}

我只是在这里写代码(可能有错误),但我想你已经明白我所做的要点了。我只是为部分添加了一层,并没有假设“from”和“to”项来自同一部分

警告: 这段代码可以工作,但如果该部分最初没有项目,我会遇到问题

希望这有帮助