5
votes

I programmatically call complete: to call NSTextView autocompletion delegate method:

- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index

I have 2 tables, one is in the main sheet, and the other one in the popup window. The popup window is modally opened from the sheet.

Both tables have the column with the same subclass of NSTextView. Both tables have as delegate the same file owner, however the delegate method is called only for the table in the main sheet.

The strange thing is that all other delegate methods are correctly called from the table in the popup window:

- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
- (BOOL)control:(NSControl *)control isValidObject:(id)object
- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

UPDATE:

About the NSTableView structure:

The tables are cell-based NSTableView. The column is made by NSTextFieldCell that I've subclassed. The code below is from the subclassed NSTextFieldCell.

The method returns another subclass, named CBAutocompleteTextField, this time inheriting from NSTextView, which is the text editor inside the cell.

- (NSTextView *)fieldEditorForView:(NSView *)aControlView
{
    return [[[CBAutocompleteTextField alloc] init] autorelease];
} 

So in the end, the class invoking complete: is a subclass of NSTextView.

1
Your description is not entirely clear. You mention a subclass of NSTextView but also NSTextField. Are you using a custom field editor? Is the table a view-based table? In that case, I guess you have an actual NSTextField, in which case what matter is the text field's delegate, not the table's delegate. If you're using an NSCell-based table view, then you would have NSTextFieldCells rather than NSTextFields and the table's delegate would be relevant.Ken Thomases
@KenThomases Sorry, the title was wrong. I've updated the question with all details about the implementation of the table. Consider the this code perfectly worked so far in the main sheet. But it fails for the new table I've added to the popup window. Other delegate methods are invoked though, which means the delegate is correctly set.aneuryzm

1 Answers

1
votes

Try this if it helps, for perform auto completion you will need to call complete: in the text fields field editor by using below delegate method:-

- (void)controlTextDidChange:(NSNotification *)notification {
    if( autoComplete ){
        return;
    } else {
        autoComplete = YES;
        [[[notification userInfo] objectForKey:@"NSFieldEditor"] complete:nil];
    }
}