出于某种原因,我收到以下错误:
*非法的 NSTableView 数据源()。必须实现 numberOfRowsInTableView: 和 tableView:objectValueForTableColumn:row:
这是我的 AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, NSTableViewDataSource, NSTableViewDelegate> {
NSMutableArray *userNotifications;
}
@property NSMutableArray *userNotifications;
@end
我的 AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize userNotifications;
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
NSUserNotification *userNotification = notification.userInfo[NSApplicationLaunchUserNotificationKey];
userNotifications = [NSMutableArray new];
if(userNotification) {
[self userActivatedNotification:userNotification];
} else {
for(int i=1; i <= 10; i++) {
NSString *title = [NSString stringWithFormat: @"Title %d", i];
NSString *message = [NSString stringWithFormat: @"Message %d", i];
NSArray *notificationObj = [[NSArray alloc] initWithObjects:title, message, nil];
// NSLog(@"Array: %@", notificationObj);
[userNotifications addObject:notificationObj];
// NSLog(@"Notifications: %@", userNotifications);
[self deliverNotificationWithTitle:title message:message];
}
}
}
- (void)deliverNotificationWithTitle:(NSString *)title
message:(NSString *)message
{
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
NSUserNotification *userNotification = nil;
userNotification = [NSUserNotification new];
userNotification.title = title;
userNotification.informativeText = message;
center.delegate = self;
[center scheduleNotification:userNotification];
}
- (void)userActivatedNotification:(NSUserNotification *)userNotification
{
// [[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:userNotification];
printf("* User activated notification:");
// NSLog(@"Title: %@", userNotification.title);just do it in
// NSLog(@"Message: %@", userNotification.informativeText);
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"https://www.google.com/"]];
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)userNotitification
{
printf("* Notification presented.");
return YES;
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
return [userNotifications count];
}
- (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
return [userNotifications objectAtIndex:row];
}
@end