我之前使用过 NSTableView 几次,并且我使用此方法没有任何问题,但由于某种原因,在我的最新程序中,tableViewSelectionDidChange:
当我切换行时没有调用委托方法。我创建了一个非常简单的程序来尝试找到它的源头,但由于某种原因它仍然无法正常工作。我知道我可能忽略了一些小东西,但我已经盯着这个看了几个小时,并将它与我的其他代码进行比较,但我什么也看不到。
AppDelegate.h:
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate, NSTableViewDataSource, NSTableViewDelegate>
//not sure if the NSTableViewDelegate part is needed, as I've used this before without it
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTableView *tableView;
@end
AppDelegate.m:
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
}
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification{
NSLog(@"Row changed");
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return 2;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
return nil;
}
@end