Subclassing NSButton

Coding Questions, IDE related or anything else

Subclassing NSButton

Postby udo.killermann » Fri Apr 30, 2010 6:09 am

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?
Attachments
windowDecoration.zip
(244.67 KiB) Downloaded 89 times
--------------
MacBook (2GHz, 4 GByte) - Lion (10.7.3)
started Objective Basic coding in April 2010 - still enjoy it ;-)
udo.killermann
 
Posts: 247
Joined: Thu Apr 08, 2010 6:46 am
Location: Hannover, Germany

Re: Subclassing NSButton

Postby berndnoetscher » Fri Apr 30, 2010 11:10 am

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.
Attachments
windowDecoration.zip
(656.07 KiB) Downloaded 93 times
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

Re: Subclassing NSButton

Postby udo.killermann » Fri Apr 30, 2010 6:07 pm

Hello Bernd,

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

Kind regards
Udo
--------------
MacBook (2GHz, 4 GByte) - Lion (10.7.3)
started Objective Basic coding in April 2010 - still enjoy it ;-)
udo.killermann
 
Posts: 247
Joined: Thu Apr 08, 2010 6:46 am
Location: Hannover, Germany


Return to Objective-Basic (Xcode 3)

Who is online

Users browsing this forum: No registered users and 1 guest

cron