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,不客氣) –