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

Coding Questions, IDE related or anything else

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

Postby udo.killermann » Wed Jan 05, 2011 7:38 am

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
Last edited by udo.killermann on Sat Jan 29, 2011 11:01 am, edited 1 time in total.
--------------
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: why can't i assign a delegate to a subview?

Postby berndnoetscher » Mon Jan 10, 2011 10:37 am

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?
berndnoetscher
Site Admin
 
Posts: 280
Joined: Fri Feb 20, 2009 11:58 am

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

Postby udo.killermann » Tue Jan 11, 2011 1:41 pm

Hi Bernd,

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

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