我有NSMutableArray
,其中包含NSMutableDictionaries
。我想在NSTableView
中显示此字典中的一个字符串。此字符串在对象中是唯一的。默认情况下这有一些已插入对象时,如果找到任何重复的字符串,则尝试显示警报并使用以下API编辑相应的行。
- (void)editColumn:(NSInteger)column row:(NSInteger)row withEvent:(NSEvent *)theEvent select:(BOOL)select;
这很好。
如果用户按下选项卡或用户按下任何其他视图(辞职FirstResponder
)而不重命名,则tableview
中的旧名称仍然存在,我想带回来行到edit mode
。如何做到这一点?
答案 0 :(得分:1)
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];
}