0

我查看了文档,但仍然没有成功实现 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.

不知道是什么问题。感谢任何帮助我知道我在这里写了很多。

笔尖文件

编辑 ——问题似乎是它找不到代表对象.图像或任何其他属性。我怎样才能解决这个问题?

在此处输入图像描述

4

2 回答 2

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
于 2013-01-23T23:20:30.690 回答
0

将阵列控制器的模式Class和类名设置为ProjectModel

于 2013-01-23T06:30:37.370 回答