2012-12-18 52 views

回答

1

是的! (一個警告)

您需要更換的委託方法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]; 

}

我只是寫代碼在這裏(它可能有錯誤),但我想你會明白我在做什麼。我只是爲部分添加一層,並且不假定「從」和「到」項來自同一部分。

警告: 此代碼有效,但如果該部分初始爲空項目,則出現問題。

希望這會有所幫助。

相關問題