UIKeyboardWillShowNotification Is always nil?

@Steppers it appears as if the keyboard notification messages aren’t actually passing the notification objects?

function setup()
    -- Hidden text field, just enough to summon keyboard
    tf = objc.UITextField()
    objc.viewer.view:addSubview_(tf)
    
    -- Minimal notification handler
    local Handler = objc.class("KBHandler")
    
    function Handler:keyboardWillShow_(notification)
        print("notification value:", notification)
    end
    
    local handler = Handler()
        objc.NSNotificationCenter.defaultCenter:addObserver_selector_name_object_(
    handler,
    objc.selector("keyboardWillShow:"),
    "UIKeyboardWillShowNotification",
    nil
    )
    
    print("Observer installed. Tap screen.")
end

function draw() end

function touched(t)
    if t.state == BEGAN then
        if tf.isFirstResponder then
            tf:resignFirstResponder_()
        else
            tf:becomeFirstResponder_()
        end
        return true
    end
end

…is that a bug or is it something intentionally left out or am I just doing it wrong to begin with?

Codea needs some added context to callbacks so it know how to bridge the callback parameters. In this case the notification is an object so prepend the parameter name with ‘o’:

function Handler:keyboardWillShow_(oNotification)
        print("notification value:", oNotification)
end
1 Like

Oooo cool! Did I miss that in the docs? Thanks!

No problem, you must have done :slight_smile:

1 Like

Ok the morbidly depressing thing is I must have read that page like five times at least and I just didn’t get it.

Thank you for explaining it!

1 Like