2013-10-14 1 views
0

저는 XcodeCapp와 함께 카푸치노 0.9.6을 사용하고 있습니다. CPImageView 하위 유형 항목 (ThumbnailView)으로 채워진 CPCollectionView가 있습니다. 이제 항목을 드래그 할 수있게하려고합니다.인터페이스 빌더를 사용하여 CPCollectionView에서 드래그 앤 드롭

Scrapbook #2 - Drag and Drop 예제의 지침을 내 xcode 인터페이스에 적용했습니다 (드래그 대상이 아직 구현되지 않음). 그러나 항목을 선택할 수 없으며 드래그 할 수 없습니다. 무엇이 잘못되었는지에 대한 아이디어가 있습니까? 엑스 코드 AppController.j

@import <Foundation/CPObject.j> 
@import "MediaController.j" 


@implementation AppController : CPObject 
{ 
    CPWindow  theWindow; //this "outlet" is connected automatically by the Cib 
    @outlet MediaController mediaController; // connected to AppController 
} 

- (void)applicationDidFinishLaunching:(CPNotification)aNotification 
{ 

    // load media 
    [mediaController loadMedia]; 
} 

- (void)awakeFromCib 
{ 
    [theWindow setFullPlatformWindow:YES]; 
} 

@end 

MediaController.j

ThumbnailDragType = @"ThumbnailDragType"; 

@implementation MediaController : CPObject 
{ 
    CPArray images; 

    // outlets 
    @outlet CPCollectionView thumbnailCollectionView; // connected to CPCollectionView in interface builder 
} 

- (id)loadMedia 
{ 
    [thumbnailCollectionView setAutoresizingMask:CPViewWidthSizable]; 
    [thumbnailCollectionView setMinItemSize:CGSizeMake(150, 150)]; 
    [thumbnailCollectionView setMaxItemSize:CGSizeMake(150, 150)]; 
    [thumbnailCollectionView setDelegate:self]; 

    var itemPrototype = [[CPCollectionViewItem alloc] init]; 

    [itemPrototype setView:[[ThumbnailView alloc] initWithFrame:CGRectMakeZero()]]; 

    [thumbnailCollectionView setItemPrototype:itemPrototype]; 

    image1 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample.jpg" size:CGSizeMake(500.0, 430.0)]; 
    [image1 setName:'bla']; 
    image2 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample2.jpg" size:CGSizeMake(500.0, 389.0)]; 
    [image2 setName:'asdfsadfdf']; 
    image3 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample3.jpg" size:CGSizeMake(413.0, 400.0)]; 
    [image3 setName:'asdfadsggewa']; 
    image4 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample4.jpg" size:CGSizeMake(500.0, 375.0)]; 
    [image4 setName:'aisdfiojf']; 
    image5 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample5.jpg" size:CGSizeMake(500.0, 375.0)]; 
    [image5 setName:'oiajdf']; 
    image6 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample6.jpg" size:CGSizeMake(500.0, 375.0)]; 
    [image6 setName:'aidsoifsd']; 

    images = [image1, image2, image3, image4, image5, image6]; 

    [thumbnailCollectionView setContent:images]; 

    return self; 
} 

- (CPData)collectionView:(CPCollectionView)aCollectionView dataForItemsAtIndexes:(CPIndexSet)indices forType:(CPString)aType 
{ 
    return [CPKeyedArchiver archivedDataWithRootObject:[images objectAtIndex:[indices firstIndex]]]; 
} 

- (CPArray)collectionView:(CPCollectionView)aCollectionView dragTypesForItemsAtIndexes:(CPIndexSet)indices 
{ 
    return [ThumbnailDragType]; 
} 

@end 





@implementation ThumbnailView : CPImageView 
{ 
    CPImageView imageView; 
    CPView labelView; 
    CPTextField label; 
} 

- (void)setSelected:(BOOL)isSelected 
{ 
    [self setBackgroundColor:isSelected ? [CPColor grayColor] : nil]; 
} 

- (void)setRepresentedObject:(id)anObject 
{ 
    if (!imageView) 
    { 
     var frame = CGRectInset([self bounds], 5.0, 5.0); 

     // make imageView 
     imageView = [[CPImageView alloc] initWithFrame:frame]; 
     [imageView setImageScaling:CPScaleProportionally]; 
     [imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; 

     [self addSubview:imageView]; 

     // make label view 
     labelView = [[CPView alloc] initWithFrame:CGRectMake(
      5.0, 
      125.0, 
      140.0, 
      20.0 
     )]; 
     [labelView setBackgroundColor:[CPColor blackColor]]; 

     // make label 
     label = [[CPTextField alloc] initWithFrame:CGRectInset([labelView bounds], 3.0, 3.0)]; 
     [label setTextColor:[CPColor whiteColor]]; 
     [labelView addSubview:label]; 

     [self addSubview:labelView]; 
    } 

    [imageView setImage:anObject]; 
    [label setStringValue:[anObject name]]; 
} 

@end 

답변

0

, 수집 뷰 "선택"으로 표시되어 있는지 확인 (첨부 이미지 참조).

enter image description here