我有以下目标C代码保持错误抱怨我重新定义它时,我不!我想实现一个NSTableViewDelegate的事情,但Xcode中不停地抱怨SidebarDelegate作为不同类型的符号的重定义
#import "AppDelegate.h"
#import <AppKit/AppKit.h>
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// add Hello World to sidebar
[self.Sidebar.tableView insertValue:0 atIndex:0 inPropertyWithKey:@"Hello World!"];
[self.Sidebar.tableView setDelegate: SidebarDelegate()]
// reload data
[self.Sidebar.tableView reloadData];
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return YES;
}
@end
// Sidebar Delage
@implementation SidebarDelegate : NSObject <NSTableViewDelegate, NSTableViewDataSource>;
// setting data
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
anObject = @"Apples";
}
// height
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
return 20;
}
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
NSLog(@"%ld", (long)rowIndex);
return ((long)rowIndex % 2) == 0;
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return 4;
}
@end