Re: Creating a criteria search view
Re: Creating a criteria search view
- Subject: Re: Creating a criteria search view
- From: Steve Palmer <email@hidden>
- Date: Wed, 21 Apr 2004 22:20:36 -0700
OK. I think I follow, except I still don't have much success. Maybe
some more code will help? Basically I'm now trying to add one new row
at a time:
// Shift the existing subviews up by rowHeight
NSArray * subviews = [searchCriteriaSuperview subviews];
for (c = 0; c < [subviews count]; ++c)
{
NSView * row = [subviews objectAtIndex:c];
NSPoint origin = [row frame].origin;
[row setFrameOrigin:NSMakePoint(origin.x, origin.y + rowHeight)];
[row setNeedsDisplay:YES];
}
// Now add the new subview
archRow = [NSArchiver archivedDataWithRootObject:searchCriteriaView];
NSRect bounds = [searchCriteriaSuperview bounds];
NSView *row = (NSView *)[NSUnarchiver unarchiveObjectWith
Data:archRow];
[row setFrameOrigin:NSMakePoint(bounds.origin.x, bounds.origin.y)];
[searchCriteriaSuperview addSubview:row];
There's other code that resizes the window by rowHeight and that's
working fine. The problem here is that as the second and subsequent
views are added, they aren't visible. I wonder if there's something
wrong with my coordinate math or I'm just missing something
fundamental?
Thanks for your help so far though!
- Steve
On Apr 21, 2004, at 12:53 AM, Louis C. Sacha wrote:
>
Hello...
>
>
Nope :) In this particular context, above and below refer to stacked
>
positions, not the two dimensional relationship between the views (it
>
refers to the z axis, if you understand what I mean by that). For
>
example, if you have a pile of papers on your desk, page 1 is above
>
page 2, page 5 is below page 4, ect... (assuming the pages are in
>
order).
>
>
Using addSubview: is usually sufficient unless you have subviews which
>
are supposed to overlap (which is generally discouraged). What you
>
want is the pages spread out on the desk, which requires changing the
>
frame of the subview instead. I'm not sure exactly why your code isn't
>
working, but a couple suggestions:
>
>
1) Try setting the frame origin before you add the view as a subview.
>
2) Don't refer to the existing frame origin of the unarchived view
>
when you are setting the frame origin (although using the height is
>
okay). You should probably use the bounds rectangle of the superview
>
as a reference (or 0.0 if that is appropriate).
>
>
NSRect bounds = [searchCriteriaSuperview bounds];
>
for (c = 0; c < totalCriteria; c++)
>
{
>
NSView *row = (NSView *)[NSUnarchiver
>
unarchiveObjectWithData:archRow];
>
[row setFrameOrigin:NSMakePoint(bounds.origin.x, bounds.origin.y + c
>
* rowHeight)];
>
[searchCriteriaSuperview addSubview:row];
>
}
>
>
Another seperate issue, which might be caused by cutting and pasting
>
code into the message for the list, but if you are running the code as
>
it is in the email, it appears that you only remove one
>
searchCriteriaView and then create the full number you need. For
>
example, if you have 2 criteria views and you tried to use this
>
version of the code to increase the number to 3, you would actually
>
end up with 4 (2-1+3). You could use the subviews method on the
>
superview of your criteria views to get an array of them so that you
>
can remove all of the views.
>
>
Hope that helps,
>
>
Louis
>
>
>
> Trying again... My specific question is: is it reasonable to assume
>
> that addSubview:positioned:relativeTo: will automatically position
>
> the new subview below the specified one without my needing to do any
>
> more? I added the setFrameOrigin because I wasn't seeing this
>
> behaviour but even that makes no difference. The views appear to be
>
> placed behind each other.
>
>
>
> - Steve
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.