2
我一直在为此奋斗三天。我在这里和谷歌上查找了所有可以找到的东西,所以请理解,我已经用尽了自己的努力来寻找答案。我也是新来的可可,所以我很抱歉,如果这似乎是微不足道的,但它不是我。我在学! :)更新NSTableView单元格上的数据源编辑
我用简单的字符串值填充NSTableView。这就是我需要的。我也需要这些值可以内联编辑。到目前为止,我已经完成了所有这些工作。
问题是,我不知道如何将这些更改保存到我的数据源。我已经尝试了所有建议的委托方法,他们要么不被调用,要么我不知道如何获取更新的值分配给我的NSMutableArray。
下面的代码:
//
// AppDelegate.m
// TableView
//
// Created by Jay Moser on 2016-03-07.
// Copyright © 2016 Jay Moser. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate()
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
{
NSMutableArray* _tableContents;
IBOutlet NSTableView* _tableView;
}
- (IBAction)Add:(id)sender
{
[_tableView reloadData];
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
_tableContents = [[NSMutableArray alloc] init];
[_tableContents addObject:@"Item 1"];
[_tableContents addObject:@"Item 2"];
[_tableContents addObject:@"Item 3"];
[_tableContents addObject:@"Item 4"];
[_tableContents addObject:@"Item 5"];
[_tableContents addObject:@"Item 6"];
[_tableContents addObject:@"Item 7"];
[_tableContents addObject:@"Item 8"];
[_tableView reloadData];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
return [_tableContents count];
}
- (NSView*)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
NSTableCellView* cellView = [_tableView makeViewWithIdentifier:@"name" owner:self];
cellView.textField.stringValue = _tableContents[row];
return cellView;
}
// ====================================================================================
//
// If I run the application, double click an item in the tableview and, for example,
// rename "Item 4" to "Renamed Item" ... I need a method here to detect that the change
// happened and changes "Item 4" in _tableContents to "Renamed Item"
//
//
// ====================================================================================
@end
你。岩。非常感谢你,完美的工作!正是我需要:) 感谢您的链接,我也一定会阅读这个答案! – jdmoser
@jdmoser,不客气) –