2012-04-16 14 views
1

私はNSMutableDictionariesを含むNSMutableArrayを持っています。この辞書の文字列をNSTableViewに表示したいと思います。この文字列はオブジェクト間で一意です。オブジェクトが挿入され、重複した文字列が見つかった場合、アラートを表示しようとし、次のAPIを使用して対応する行を編集しようとしました。NSTableViewでNSAlertsを使用して重複行を編集する

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

これが正常に動作します。ユーザーがタブを押すか、名前を変更せずに他のビュー上のユーザーを押すが、(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]; 
} 
関連する問題