我正在构建基于文档的Mac应用程序.我有两个类myDocument和Person.我遇到的困难是当我按下按钮在表视图中添加一个新Person并显示它时它不会在表视图中显示.我已将日志语句放在委托方法中.由于我的日志语句没有显示在控制台中,我知道它们没有被调用.以下是委托方法的实现
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [employees count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
// What is the identifier for the column?
NSString *identifier = [aTableColumn identifier];
NSLog(@"the identifier's name is : %s",identifier);
// What person?
Person *person = [employees objectAtIndex:rowIndex];
// What is the value of the attribute named identifier?
return [person valueForKey:identifier];
}
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
NSString *identifier = [aTableColumn identifier];
Person *person = [employees objectAtIndex:rowIndex];
NSLog(@"inside the setObjectMethod: %@",person);
// Set the value for the attribute named identifier
[person setValue:anObject forKey:identifier];
[tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
这是我的.xib图片
这是我的行动方法
#pragma mark Action Methods
-(IBAction)createEmployee:(id)sender
{
Person *newEmployee = [[Person alloc] init];
[employees addObject:newEmployee];
[newEmployee release];
[tableView reloadData];
NSLog(@"the new employees name is : %@",[newEmployee personName]);
}
-(IBAction)deleteSelectedEmployees:(id)sender
{
NSIndexSet *rows = [tableView selectedRowIndexes];
if([rows count] == 0){
NSBeep();
return;
}
[employees removeObjectAtIndexs:rows];
[tableView reloadData];
Run Code Online (Sandbox Code Playgroud)
}