Search code examples
objective-cmacoscocoanstokenfield

NSTokenField selection list shows empty space while scrolling


While using NSTokenField something strange is happening, as shown in the images below :

As I type A, selection from popup is shown.

As I type A

I scrolled it

enter image description here

Some more scroll, and it went below the visible area.

enter image description here

This is a behaviour with all the tableviews. The view behind the rows are visible , but it automatically springs to normal position. But not in this case.

It is fine in Mail app, it is working fine.

My implementation is :

  1. Created an NSTokenField.

  2. Set its delegate to AppDelegate.

  3. In the implementation file

     -(NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex{
        return @[@"A",@"B",@"C"];
    }
    

Even the sample code from apple documentation behaves incorrectly.

How can I make it auto-spring or restrict by some code?


Solution

  • What you see in Mail.app is not an actual NSMenu (Apple cheats, shocking!). Turns out, it's actually a custom NSTextField linked to an NSTableView stuck in a transparent window.

    F-Scripting FTW

    It's a fairly old trick to get around the extremely poor version of scrollWheel: NSMenu happens to have implemented. MTTokenField is a mature alternative to pulling your hair out trying to stick a scroll view in an NSMenu.