0

我已經看過documentation但我仍然沒有成功實現CollectionView。這是我的。NSCollectionView實現

我的KVO/KVC兼容的NSMutableArray。

#import <Foundation/Foundation.h> 
#import "ProjectModel.h" 

@interface KVOMutableArray : NSMutableArray 

@property NSMutableArray* projectModelArray; 

- (id)init; 
- (void)insertObject:(ProjectModel *)p inProjectModelArrayAtIndex:(NSUInteger)index; 
- (void)removeObjectFromProjectModelArrayAtIndex:(NSUInteger)index; 
- (void)setProjectModelArray:(NSMutableArray *)a; 
- (NSArray*)projectModelArray; 

@end 

ProjectModel.h文件:

#import <Foundation/Foundation.h> 

@interface ProjectModel : NSObject { 
    NSString *applicationName; 
    NSString *projectPath; 
    NSImage *image; 
} 

@property(retain, readwrite) NSImage *image; 
@property(retain, readwrite) NSString *applicationName; 
@property(retain, readwrite) NSString *projectPath; 
@end 

ProjectModel.m:

#import "ProjectModel.h" 

@implementation ProjectModel 

@synthesize image; 
@synthesize projectPath; 
@synthesize applicationName; 

- (id)init { 
    self = [super init]; 
    image = [NSImage imageNamed:@"xcodeproject.png"]; 
    return self; 
} 

@end 

我也把@property KVOMutableArray *projectsManager;我AppDelegate.h文件和

projectsManager = [[KVOMutableArray alloc] init]; 
ProjectModel *pm1 = [[ProjectModel alloc] init]; 
pm1.projectPath = @"path here"; 
pm1.applicationName = @"Crittercism Example App"; 
[projectsManager addObject: pm1]; 

我awakeFromNib方法。 我得到以下異常,然後將其終止:

[<NSCollectionViewItem 0x1001c2eb0> addObserver:<NSAutounbinderObservance 0x1001e2a20> forKeyPath:@"representedObject.applicationName" options:0x0 context:0x103111690] was sent to an object that is not KVC-compliant for the "representedObject" property. 

不知道是什麼問題。任何幫助表示讚賞我知道我在這裏寫了很多。

Nib file

Edit-- 這個問題似乎是,它無法找到representObject.image或任何其他屬性爲此事的。我怎樣才能解決這個問題?

enter image description here

+0

我想知道爲什麼我得到-1? 該文件說我只需要4種方法,當我真的需要超過4種方法... – Nonconformist

回答

1

它的工作,我實現後,這些方法(原來的文檔說謊只需要4種方法,他們認爲那裏) :

#import <Foundation/Foundation.h> 
#import "ProjectModel.h" 

@interface KVOMutableArray : NSMutableArray { 
    NSMutableArray *projectModelArray; 
} 
@property (readonly, copy) NSMutableArray* projectModelArray; 

- (id)init; 
- (void)insertObject:(ProjectModel *)p; 
- (void)insertObject:(id)p inProjectModelArrayAtIndex:(NSUInteger)index; 
- (void)removeObjectFromProjectModelArrayAtIndex:(NSUInteger)index; 
- (void)setProjectModelArray:(NSMutableArray *)array; 
- (NSUInteger)countOfProjectModelArray; 
- (id)objectInProjectModelArrayAtIndex:(NSUInteger)index; 
- (void)insertProjectModelArray:(NSArray *)array atIndexes:(NSIndexSet *) indexes; 
- (NSArray *)projectModelArrayAtIndexes:(NSIndexSet *)indexes; 
- (NSArray*)projectModelArray; 
- (void)removeProjectModelArrayAtIndexes:(NSIndexSet *)indexes; 
- (NSUInteger)count; 
- (void)insertObject:(id)object atIndex:(NSUInteger)index; 

@end 
+0

爲什麼我會陷入低谷......我讓人們知道文檔是錯誤的...... – Nonconformist

+0

該文檔確實是錯誤的。我實現了我自己的KVOMutableArray,並找到了同樣的謊言(https://github.com/haifengkao/KVOMutableArray)。 –

0

設置你的陣列控制器Class的模式和類名ProjectModel

+0

我做到了,沒有骰子。 – Nonconformist