Page 1 of 1

DONE: why can't i assign a delegate to a subview?

PostPosted: Wed Jan 05, 2011 7:38 am
by udo.killermann
Board,

within UKWindow a class derived from NSWindow I use the follwing code:
Code: Select all
Dim theSubviews As Array
Dim currentSubview As NSView
Dim theImageViews As Array
Dim currentImageView As NSImageView
' Dim theObject As NSObject
Dim counter As Integer
Dim numberOfSubviews As Integer
Dim images As Array("erdmann.jpg", "wein.jpg")

Dim player1View As NSView

' Declare Delegate "NSView" - (void)mouseDown:(NSEvent *)event sender:(id)control
Declare Function "NSEvent" - (NSPoint)locationInWindow

Declare Sub "NSView" - (void)setDelegate:(id)del

Event AwakeFromNib()
  numberOfSubviews = 4

'  theMainView.Delegate = Me
  ' Me.Delegate=Me
  For counter = 0 To numberOfSubviews-1
    currentSubview = NSView()
    currentSubview.setFrame(Rect(50+(counter*110),50,100,100))
    theSubviews.Append(currentSubview)
   
    currentImageView = NSImageView(images.Object(counter Mod 2))
    ' currentImageView.ImageScaling = 1
    currentImageView.setFrame(Rect(0, 0, 100, 100))

    Log(images.Object(counter Mod 2))
    theImageViews.Append(currentImageView)
   
    currentSubview.addSubview(currentImageView)
    ' currentSubview.Delegate = Me  ' << offendig line

    theMainView.addSubview(currentSubview)   
  Next
  player1View = NSView()
  player1View.setFrame(Rect(450, 300, 100, 100))
  theMainView.addSubview(player1View)
End Event


With "currentSubview.Delegate = Me" I want to assign the same event handler for all subviews within the main view. Could you please give a hint, how to handle this.

Thanks
Udo

Re: why can't i assign a delegate to a subview?

PostPosted: Mon Jan 10, 2011 10:37 am
by berndnoetscher
Hi Udo,

back from vacation and have a lot of work on my desktop... ;-)

Where did you find the declaration of

Declare Sub "NSView" - (void)setDelegate:(id)del

in the Cocoa manuals?

Re: why can't i assign a delegate to a subview?

PostPosted: Tue Jan 11, 2011 1:41 pm
by udo.killermann
Hi Bernd,

I was mistaken: a NSView doesn't have a delegate.

Regards
Udo