J'ai regardé le documentation mais je n'ai toujours pas réussi à implémenter un CollectionView. Voici ce que j'ai.Implémentation de NSCollectionView
Mon NSMutableArray conforme à KVO/KVC.
#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
fichier 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
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
J'ai aussi mis @property KVOMutableArray *projectsManager;
dans mon fichier AppDelegate.h et
projectsManager = [[KVOMutableArray alloc] init];
ProjectModel *pm1 = [[ProjectModel alloc] init];
pm1.projectPath = @"path here";
pm1.applicationName = @"Crittercism Example App";
[projectsManager addObject: pm1];
dans mon méthode awakeFromNib. Je reçois l'exception suivante puis il se termine:
[<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.
Je ne sais pas quel est le problème. Toute aide est appréciée Je sais que j'ai beaucoup écrit ici.
Edit-- Le problème semble qu'il ne peut pas trouver representObject.image ou l'une des autres propriétés de cette matière. Comment puis-je réparer cela?
Je voudrais savoir pourquoi je reçois un -1? La documentation dit que j'avais seulement besoin de 4 méthodes quand j'avais réellement besoin de plus de 4 méthodes ... – Nonconformist