gpt4 book ai didi

objective-c - 在 NSTableView 中使用 NSAlerts 编辑重复行

转载 作者:行者123 更新时间:2023-12-03 17:14:44 24 4
gpt4 key购买 nike

我有一个 NSMutableArray,其中包含 NSMutableDictionaries。我想在 NSTableView 中显示此字典中的一个字符串。该字符串是唯一的默认情况下,它具有一些已知值。插入对象时,如果发现任何重复字符串,则尝试显示警报并使用以下 API 编辑相应的行。

- (void)editColumn:(NSInteger)列行:(NSInteger)行 withEvent:(NSEvent *)theEvent select:(BOOL)select;

这工作正常。

如果用户按下选项卡或按下任何其他 View (放弃FirstResponder)而不重命名,旧名称仍然存在于tableview中,我想将此行恢复到编辑模式。如何实现这一点?

最佳答案

I was able to solve the issue.Modified the alert using sheets.
Following code worked for me.

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
if(duplicate)//duplicatefound
{
[self showAlertForDuplicates];
}
}


// Selector

- (void)duplicateAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
if (returnCode == NSAlertFirstButtonReturn)
{
[self.tableView editColumn:0 row:self.selectedRow withEvent:nil select:NO];
}
}

-(void) showAlertForDuplicates
{
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"Ok"];
[alert setMessageText: @"DuplicateName"];
[alert setInformativeText: @"Rename the item")];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert beginSheetModalForWindow:nil modalDelegate:self didEndSelector:@selector(duplicateAlertDidEnd:returnCode:contextInfo:) contextInfo:nil];
}

关于objective-c - 在 NSTableView 中使用 NSAlerts 编辑重复行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10174899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com