0

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.

Nib file

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?

enter image description here

+0

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

Répondre

1

Il a travaillé après avoir appliqué ces méthodes (se révèle la documentation a menti sur seulement besoin des 4 méthodes qu'ils y suggéraient) :

#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 
+0

Pourquoi je reçois downview ... Je fais savoir aux gens que la documentation était erronée ... – Nonconformist

+0

la documentation est en effet erronée. J'ai implémenté mon propre KVOMutableArray et j'ai trouvé le même mensonge (https://github.com/haifengkao/KVOMutableArray). –

0

Réglez le mode de votre contrôleur RAID Class et le nom de classe à ProjectModel

+0

Je l'ai fait, pas de dés. – Nonconformist

Questions connexes