Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Using NSView addSubview:

Using NSView addSubview:
Thread Tools
djohnson
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Feb 24, 2004, 03:18 PM
 
In my latest program, I am adding NSViews. There is something similiar to this:

while(I get the next thing)
{
NSView* view = [nextthing theView];
NSRange frame = [view bounds];
[view setFrame:NSMakeRect(0.0,height,112.0,frame.size.he ight)];
[theView addSubview:view positioned:1 relativeTo:nil];
[theView setNeedsDisplay:YES];
height += frame.size.height;
}

This will add my view that I am getting and place it in my theView which is the view of the window. Everything displays great, what I am having problems with is that only the latest NSView will accept mouse clicks. Now here are my thoughts:

1. I obtain the click in the window then find out if is inside of a NSRect and if that NSRect corresponds to one of the views. If it does, then I will need to switch to that view and let it do its thing.

I do not know how to switch to that view. Any ideas or am I going down the wrong trail?
     
Mskr
Forum Regular
Join Date: Jun 2001
Location: Savoy, IL USA
Status: Offline
Reply With Quote
Feb 24, 2004, 06:30 PM
 
Originally posted by djohnson:
In my latest program, I am adding NSViews. There is something similiar to this:

while(I get the next thing)
{
NSView* view = [nextthing theView];
NSRange frame = [view bounds];
[view setFrame:NSMakeRect(0.0,height,112.0,frame.size.he ight)];
[theView addSubview:view positioned:1 relativeTo:nil];
[theView setNeedsDisplay:YES];
height += frame.size.height;
}

This will add my view that I am getting and place it in my theView which is the view of the window. Everything displays great, what I am having problems with is that only the latest NSView will accept mouse clicks. Now here are my thoughts:

1. I obtain the click in the window then find out if is inside of a NSRect and if that NSRect corresponds to one of the views. If it does, then I will need to switch to that view and let it do its thing.

I do not know how to switch to that view. Any ideas or am I going down the wrong trail?
What kind of NSView or NSView subclasses is this? If you're directly subclassing NSView, make sure that you override acceptsFirstMouse:. If it's some kind of NSControl or whatever, that shouldn't matter, I guess. Anyway, you shouldn't need to do anything to mouseDown: in the window; the event should get propagated properly to the subviews, if you're doing everything else correctly.

The reason that the last view added might be getting the mouse clicks is that it's become the first responder. Maybe look into that angle, as well.

Maybe if you could post a little more info on what the subviews that you're adding actually are, and what you're trying to accomplish, that might be helpful.
Software Architect, CodeTek Studios, Inc.

12" AlBook 867 (Combo drive) 640 MB/40 GB (work development machine) -- TiBook 400MHz/384MB/10GB (home machine)
CodeTek VirtualDesktop Pro: Power multitasking! -- DockExtender: Powerful, efficient launcher for Apps, Docs and everything else!
     
djohnson  (op)
Professional Poster
Join Date: Sep 2000
Location: Texas
Status: Offline
Reply With Quote
Feb 24, 2004, 08:32 PM
 
Sure, the subviews are buttons. This is why it is messing with my head... I am directly subclassing NSView. Does this help any?
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:50 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,