我已經看過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.
不知道是什麼問題。任何幫助表示讚賞我知道我在這裏寫了很多。
Edit-- 這個問題似乎是,它無法找到representObject.image或任何其他屬性爲此事的。我怎樣才能解決這個問題?
我想知道爲什麼我得到-1? 該文件說我只需要4種方法,當我真的需要超過4種方法... – Nonconformist