Can IMKCandidates `setCandidateData:` be used in place of IMKInputController `candidates:` delegate method?

227 Views Asked by At

I'm creating an IMKCandidate candidate window for my Input Method Kit input method:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/IMKCandidates_Class/

You then need to override the IMKInputController methods candidateSelectionChanged: and candidateSelected: as well as implement a candidates method in your delegate object. The IMKInputController subclass supplies candidates to the IMKCandidates object by implementing the candidates method. When you are ready to display a candidates window, call the candidates method to update candidates and to show the candidates window.

I've implemented the IMKInputController candidates: method to supply the array of candidates. This works great.

- (NSArray *)candidates:(id)sender {
    return @[@"`candidates:` method", @"This works great!"];
}

<code>candidates:</code> method

But I notice that a setCandidateData: method was added to set the candidate strings, as an alternative to relying on the delegate method. This would be more convenient in my input method.

@abstract Set the candidates data directly rather than supplying data via [IMKInputContoller candidates:].

-(void)setCandidateData:(NSArray*)candidatesArray AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER;

So I comment out the candidates: method, and use setCandidateData: instead:

[candidates setCandidateData:@[@"`setCandidateData:` method", @"Doesn't work :("]];
[candidates show:kIMKLocateCandidatesBelowHint];

However, when doing it this way no candidate window is shown:

enter image description here

I also see this error via the Console:

CandidateWindowNoCandidatesException : IMKCandidates show: could not get candidate strings.

The docs seem pretty clear that setCandidateData: can be used in place of candidates:. Why then are the candidates not displayed?

0

There are 0 best solutions below