首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSCollectionView实现

NSCollectionView实现
EN

Stack Overflow用户
提问于 2013-01-23 00:18:04
回答 2查看 637关注 0票数 0

我看过文档,但仍然没有成功地实现CollectionView。这是我所拥有的。

我的KVO/KVC兼容的NSMutableArray。

代码语言:javascript
复制
#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文件:

代码语言:javascript
复制
#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:

代码语言:javascript
复制
#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文件中,并且

代码语言:javascript
复制
projectsManager = [[KVOMutableArray alloc] init];
ProjectModel *pm1 = [[ProjectModel alloc] init];
pm1.projectPath = @"path here";
pm1.applicationName = @"Crittercism Example App";
[projectsManager addObject: pm1];

用我的awakeFromNib方法。我得到以下异常,然后它终止:

代码语言:javascript
复制
[<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或任何其他属性。我怎么才能解决这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-23 23:20:30

在我实现了这些方法之后,它起了作用(原来文档中只提供了他们建议的4种方法):

代码语言:javascript
复制
#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
票数 1
EN

Stack Overflow用户

发布于 2013-01-23 06:30:37

将数组控制器Class的模式和类名设置为ProjectModel

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14470411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档