Question

I have looked at the documentation yet I still haven't successfully implemented a CollectionView. Here is what I have.

My KVO/KVC compliant 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 file:

#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

I also put @property KVOMutableArray *projectsManager; in my AppDelegate.h file and

projectsManager = [[KVOMutableArray alloc] init];
ProjectModel *pm1 = [[ProjectModel alloc] init];
pm1.projectPath = @"path here";
pm1.applicationName = @"Crittercism Example App";
[projectsManager addObject: pm1];

in my awakeFromNib method. I get the following exception and then it terminates:

[<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.

Not sure what is the problem. Any help is appreciated I know I've written a lot here.

Nib file

Edit-- The problem seems to be that it can't find representObject.image or any of the other properties for that matter. How can I fix this?

enter image description here

Was it helpful?

Solution

It worked after I implemented these methods (turns out the documentation lied about only needing the 4 methods they suggested there):

#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

OTHER TIPS

Set the mode of your array controller Class and the class name to ProjectModel

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top