2012-04-16 70 views
1

重複行我有一個包含NSMutableDictionaries。我想從這個字典中NSTableView。這個字符串顯示一個字符串NSMutableArray是唯一的中objects.By默認這個有一些已知值。插入對象時,如果找到任何重複的字符串,則嘗試顯示警報並使用以下API編輯相應的行。編輯使用NSAlerts在NSTableView的

- (void)editColumn:(NSInteger)column row:(NSInteger)row withEvent:(NSEvent *)theEvent select:(BOOL)select;

這工作得很好。

如果用戶按下Tab或者其他視圖用戶按下,(辭職FirstResponder)不重命名,舊名稱仍然存在於tableview,我要帶回此行edit mode。如何做到這一點?

回答

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]; 
} 
相關問題