我看过文档,但仍然没有成功地实现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;
@endProjectModel.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;
@endProjectModel.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.不知道是什么问题。任何帮助都很感激,我知道我在这里写了很多。

编辑--,问题似乎是它找不到representObject.image或任何其他属性。我怎么才能解决这个问题?

发布于 2013-01-23 23:20:30
在我实现了这些方法之后,它起了作用(原来文档中只提供了他们建议的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发布于 2013-01-23 06:30:37
将数组控制器Class的模式和类名设置为ProjectModel
https://stackoverflow.com/questions/14470411
复制相似问题