我查看了文档,但仍然没有成功实现 CollectionView。这就是我所拥有的。
我的 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
项目模型.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.
不知道是什么问题。感谢任何帮助我知道我在这里写了很多。
编辑 ——问题似乎是它找不到代表对象.图像或任何其他属性。我怎样才能解决这个问题?