Page 1 of 1

Subclassing NSButton

PostPosted: Fri Apr 30, 2010 6:09 am
by udo.killermann
Hello Board,

to add some behaviour to the original NSButton class I thought subclassing would be a could idea. So I come up with UKButton.NSButton with the following code:
Code: Select all
Private Dim myDuration As Integer

Public Sub setTimer(theDuration As Integer)
  myDuration = theDuration
  Alert("What to do?")
  Log("setTimer")
  Log(myDuration) 
End Sub

Public Function getTimer() As Integer
  Log("GetTimer")
  Log(myDuration)
  Return myDuration
End Function


Now I have two method accessible from the outside and try to use them within my windows class UKWindow.NSWindow which is derived from NSWindow.
Code: Select all
IBOutlet myButton As UKButton

Event Init()
  Alert("UKWindow init")
End Event

IBAction ukButtonPressed(sender As id)
  Alert("Button Pressed!")
  myButton.setTimer(30)
End IBAction


The code compiles and runs without throwing an exception. But the UKButton methods are not activated although the invocation pretends to work.

I attach the project for you to see the connection between UI and code. The button in question is the lower one. The other one changes color when pressed and plays a submarine ping sound (attributes set via IB).

Kind regards
Udo

BTW: Is there an UI monitor that shows messages flowing between UI elements?

Re: Subclassing NSButton

PostPosted: Fri Apr 30, 2010 11:10 am
by berndnoetscher
Hello Udo,

fixed your example. You forgot to connect the iboultet of the button in ib

Code: Select all
IBOutlet myButton As UKButton


After that it works.

Re: Subclassing NSButton

PostPosted: Fri Apr 30, 2010 6:07 pm
by udo.killermann
Hello Bernd,

thanks for your help! The problem was between the ears :P

Kind regards
Udo