をサブクラス化する必要がありUICollectionViewFlowLayoutます。次に、必要なアクション (名前を変更する) が実行さindexPathれると、編集が必要なセルの をレイアウトに渡します。
次に、次のように、必要なレイアウト属性を追加できます。
-(void)applyRenameAttributes:(UICollectionViewLayoutAttributes *)attributes
{
if (self.renameIndexPath != nil) {
if (attributes.indexPath == self.renameIndexPath) {
// add attributes for the item that needs to be renamed
} else {
attributes.hidden = YES;
}
}
}
-(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *allAttributes = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in allAttributes) {
[self applyRenameAttributes:attributes];
}
return allAttributes;
}
-(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];
[self applyRenameAttributes:attributes];
return attributes;
}
renameIndexPathまた、値が変更されたときにレイアウトを無効にする必要があります(セッターで行います)。名前の変更が終了 (またはキャンセル) したら、renameIndexPath背面を に変更しnilます。