NSCollectionView不起作用

时间:2015-03-04 19:43:58

标签: objective-c cocoa cocoa-bindings

我的NSCollectionView有问题。 根据这本手册(https://www.youtube.com/watch?v=dw-sHMTsMVs),在我看来这很简单。

我创建了NSCollectionView,NSArrayController,它绑定了NSMuttableArray * todoList并设置了Todo类。 我使用IBAOutlet NSArrayController加入了ViewController。一切似乎都没问题,但是当我调用[arrayController addobject:todo]时,它会引发异常。看到。图片。

ViewController.h:

#import <Cocoa/Cocoa.h>

@interface ViewController : NSViewController{
    IBOutlet NSArrayController *todoArrayController;
}
@property NSMutableArray *todoList;
@property IBOutlet NSImageView *logo;

@end

ViewController.m:

#import "ViewController.h"
#import "Db.h"
#import "TodoManager.h"

@interface NSURL (NSObject)
+(id)URLWithLocalDatabase:(NSString* )database username:(NSString* )username params:(NSDictionary* )params;
+(id)URLWithHost:(NSString* )host ssl:(BOOL)ssl username:(NSString* )username database:(NSString* )database  params:(NSDictionary* )params;
+(id)URLWithHost:(NSString* )host port:(NSUInteger)port ssl:(BOOL)ssl username:(NSString* )username database:(NSString* )database params:(NSDictionary* )params;
@end

@implementation ViewController
@synthesize logo;
@synthesize todoList = _todoList;
const int WINDOW_WIDTH = 300;
TodoManager* todoManager;

- (void)awakeFromNib{
    Todo *todo = [[Todo alloc]init];
    todo.name = @"Shit";
    _todoList = [[NSMutableArray alloc]init];
    [todoArrayController addObject:todo];

}

- (void)viewDidLoad {
    todoManager = [[TodoManager alloc] init];
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)setRepresentedObject:(id)representedObject {
    [super setRepresentedObject:representedObject];
    // Update the view, if already loaded.
}

- (void)notifikace:(id)sender{
    NSUserNotification *notification = [NSUserNotification alloc];
    notification.title = @"Kurva to je dobry";
    notification.informativeText = @"TOTO je kurvesky dobrej text";
    notification.soundName = NSUserNotificationDefaultSoundName;
    [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}

- (void)viewDidAppear{
    //Nastaveni rozmeru a pozici okna
    NSRect rozmery = NSMakeRect([[NSScreen mainScreen] frame].size.width - WINDOW_WIDTH, 0, WINDOW_WIDTH, [[NSScreen mainScreen] frame].size.height);
    [self.view.window setFrame:rozmery display:true];


    //Nastaveni pozadi okna
    [self.view.window setBackgroundColor:[NSColor whiteColor]];
    //Vždy top
    [self.view.window setLevel:NSFloatingWindowLevel];

    //Nastaveni loga
    NSImage *image = [[NSImage alloc] initWithContentsOfFile:@"/Users/jasin/Documents/XcodeProjects/TestProjekt/TestProjekt/logo.png"];
    [self.logo setImage: image];

}
@end

布局&amp;连接:http://www.jumina.cz/shot1.png

1 个答案:

答案 0 :(得分:0)

请不要使用图像作为信息,例如异常日志,主要是文本。

无论如何,异常是“NSCollectionView项目原型不能为零”。因此,您忽略了将集合视图的itemPrototype出口连接到NIB中的NSCollectionViewItem实例。当您将集合视图拖动到NIB时,IB会创建集合视图项目原型并为您连接插座,因此您可能自己删除了项目和/或断开了插座。如果是这样,你就不应该。