私は並べ替えるNSCollectionViewを持っています。 Flow Layout、Delegate、およびDatasourceを使用していますが、ViewControllerに設定されています。 は、私も自分のドラッグタイプを登録しているが、私は唯一のためのデリゲートの呼び出しを取得:他のデリゲートの呼び出しのためNSCollectionViewの並べ替え(フローレイアウト)
- (BOOL)collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event;
でもありません。ここに私のViewControllerのソースコードがあります:
#import "ViewController.h"
#import "CollectionViewItem.h"
@interface ViewController()
@property(nonatomic, strong) NSArray *strings;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
}
- (void)awakeFromNib
{
self.strings = @[@"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h"];
NSArray *supportedTypes = [NSArray arrayWithObjects:@"CustomDDType", nil];
[self.collectionView registerForDraggedTypes:supportedTypes];
}
#pragma mark CollectionView DataSource
- (NSInteger) numberOfSectionsInCollectionView:(NSCollectionView *)collectionView
{
return 1;
}
- (NSInteger) collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.strings.count;
}
- (NSCollectionViewItem *) collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewItem *item = [collectionView makeItemWithIdentifier:@"CollectionViewItem" forIndexPath:indexPath];
item.myTitle.stringValue = [self.strings objectAtIndex:indexPath.item];
return item;
}
#pragma mark Drag/Drop
- (BOOL)collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event {
NSLog(@"canDragItems");
return YES;
}
-(NSDragOperation)collectionView:(NSCollectionView *)collectionView validateDrop:(id<NSDraggingInfo>)draggingInfo proposedIndex:(NSInteger *)proposedDropIndex dropOperation:(NSCollectionViewDropOperation *)proposedDropOperation {
NSLog(@"Validate Drop");
return NSDragOperationMove;
}
-(BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard
{
NSLog(@"Write Items at indexes : %@", indexes);
NSData *indexData = [NSKeyedArchiver archivedDataWithRootObject:indexes];
[pasteboard declareTypes:@[@"CustomDDType"] owner:self];
[pasteboard setData:indexData forType:@"CustomDDType"];
return YES;
}
- (BOOL)collectionView:(NSCollectionView *)collectionView acceptDrop:(id<NSDraggingInfo>)draggingInfo index:(NSInteger)index dropOperation:(NSCollectionViewDropOperation)dropOperation {
NSLog(@"Accept Drop");
NSPasteboard *pBoard = [draggingInfo draggingPasteboard];
NSData *indexData = [pBoard dataForType:@"CustomDDType"];
NSIndexSet *indexes = [NSKeyedUnarchiver unarchiveObjectWithData:indexData];
NSInteger draggedCell = [indexes firstIndex];
return YES;
}
@end
私は何かを見逃しましたか?プロジェクトを以前に実行する必要があるため、10.11で導入された新しいデリゲートコールを使用することはできません。
10.11より前にフローレイアウトを使用できますか? – Willeke
そのヒントありがとうございます。私はそれが不可能だと思う。現在、コレクションビューをコンテンツ配列のレイアウトに変更しています。 – Matt
私は同じ問題があり、それは私を怒らせます。その間に何か解決策を見つけましたか? – JFS