Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 为什么我的NSTableView数据源是非法的?_Objective C_Nstableview - Fatal编程技术网

Objective c 为什么我的NSTableView数据源是非法的?

Objective c 为什么我的NSTableView数据源是非法的?,objective-c,nstableview,Objective C,Nstableview,由于某些原因,我得到以下错误: *NSTableView数据源()非法。必须实现numberOfRowsInTableView:和tableView:objectValueForTableColumn:行: 这是我的AppDelegate.h #import <Cocoa/Cocoa.h> @interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, NS

由于某些原因,我得到以下错误:

*NSTableView数据源()非法。必须实现numberOfRowsInTableView:和tableView:objectValueForTableColumn:行:

这是我的AppDelegate.h

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, NSTableViewDataSource, NSTableViewDelegate> {

    NSMutableArray *userNotifications;
}

@property NSMutableArray *userNotifications;

@end
#导入
@接口AppDelegate:NSObject{
NSMutableArray*用户通知;
}
@属性NSMutableArray*用户通知;
@结束
我的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
#导入“AppDelegate.h”
@实现AppDelegate
@综合用户通知;
-(无效)ApplicationIDFinishLaunching:(NSNotification*)通知
{
NSUserNotification*userNotification=notification.userInfo[NSApplicationLaunchUserNotificationKey];
userNotifications=[NSMutableArray new];
如果(用户通知){
[self-userActivatedNotification:userNotification];
}否则{

对于(int i=1;i我必须将我的App Delegate设置为表视图的数据源。一旦设置了,错误就消失了。

为什么在函数体的左括号前都有分号?我不知道这是否是您的问题,但您真的想使用[userNotifications addObject:notificationObj]哪个会将notificationObj数组作为userNotifications中的一个元素添加,或者您想使用addObjectsFromArray:哪个会分别添加这两个对象?@HO2CO3:我想这是在我复制和粘贴的示例中。我复制并粘贴了您的代码,没有出现任何错误。我会弹出10个新通知,但我的表中没有任何内容view.BTW,您是否将应用程序委托设置为表视图的数据源?我必须向表视图添加一个出口,并在应用程序WillFinishMethod的末尾调用reload data(我认为表视图是在您在该方法中执行其他操作之前加载的,所以这就是为什么没有显示)。我仍然没有得到任何结果,但()但是在表视图中,因为在数据源方法中返回的是数组而不是字符串