NSCollectionView 不会工作
NSCollectionView won't work
我对 NSCollectionView 有疑问。
根据这个手册(https://www.youtube.com/watch?v=dw-sHMTsMVs),这在我看来很简单。
我创建了 NSCollectionView、NSArrayController,我绑定了 NSMuttableArray * todoList 并设置了 Todo class。
我加入 ViewController 与 IBAOutlet NSArrayController。一切似乎都很好,但是当我调用 [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
请不要使用图像作为信息,例如主要是文本的异常日志。
无论如何,例外是"NSCollectionView item prototype must not be nil"。因此,您忽略了将集合视图的 itemPrototype
出口连接到 NIB 中 NSCollectionViewItem
的实例。当您将集合视图拖入 NIB 时,IB 会创建集合视图项目原型并为您连接插座,因此您可能删除了项目 and/or 自己断开了插座。如果是这样,你不应该。
我对 NSCollectionView 有疑问。 根据这个手册(https://www.youtube.com/watch?v=dw-sHMTsMVs),这在我看来很简单。
我创建了 NSCollectionView、NSArrayController,我绑定了 NSMuttableArray * todoList 并设置了 Todo class。 我加入 ViewController 与 IBAOutlet NSArrayController。一切似乎都很好,但是当我调用 [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
请不要使用图像作为信息,例如主要是文本的异常日志。
无论如何,例外是"NSCollectionView item prototype must not be nil"。因此,您忽略了将集合视图的 itemPrototype
出口连接到 NIB 中 NSCollectionViewItem
的实例。当您将集合视图拖入 NIB 时,IB 会创建集合视图项目原型并为您连接插座,因此您可能删除了项目 and/or 自己断开了插座。如果是这样,你不应该。