Question

I have a NSMutableArray which contains NSMutableDictionaries.I would like to display one string from this dictionary in a NSTableView.This string is unique among the objects.By default this has some known value.When an object is inserted and if there is any duplicate string found,tried to show an alert and edited the corresponding row using the following API.

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

This Works fine .

If the user presses the tab or if the user presses on any other view,(resign FirstResponder) without renaming,the old name is still there in the tableview, I want to bring back this row to edit mode. How to accomplish this?

Was it helpful?

Solution

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];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top