FROM : Dave Hersey
DATE : Sat Dec 01 07:21:32 2007
> On Nov 30, 2007, at 10:18, Vince Ackerman wrote:
>
>> Sorry, I was using Bounds instead of Frame... but it still
>> doesn't change the behavior with the array. Here are the two
>> methods I'm using:
>>
>> /* Changing frame (which is what happens when the window is
>> resized) should cause relayout.
>> */
>> - (void)setFrameSize:(NSSize)size {
>> [super setFrameSize:size];
>> [self resizeDayViews: size];
>> }
>>
>>
>> -(void)resizeDayViews: (NSSize) size // Adjust all subViews for
>> size of Main view
>> {
>> NSArray *subDayViews = [self subviews]; // get array of all
>> subviews
>> NSEnumerator *enumerator = [subDayViews objectEnumerator]; // get
>> enumerator to step through the subview array
>>
>> NSRect newFrame = [self frame]; // get current bounds rect
>> NSRect newRect;
>>
>>
>> float dayWidth = ( (newFrame.size.width - 9) / 7);
>> float weekHeight = ( (newFrame.size.height - 9) / 6) ;
>> int x,y,rowCnt, columnCnt;
>>
>> NSLog( @"Start of Resize Method------------------------------");
>>
>> // for each row of days
>> for (y = 5, rowCnt = 0; rowCnt < 6; y = y + weekHeight,
>> rowCnt++)
>> {
>> for(x = 5, columnCnt = 0; columnCnt < 7; x = x + dayWidth,
>> columnCnt++)
>> {
>> newRect = NSMakeRect(x, y, dayWidth, weekHeight );
>> DayView *tempView = [enumerator nextObject];
>> [ tempView setFrame: newRect ];
>> NSLog( @"frame set");
>> NSLog( @"%@", [NSString stringWithFormat:@"%i", [tempView
>> gridNum] ]);
>> NSLog(@"%@", NSStringFromRect(newRect) );
>>
>> NSLog(@"%@", NSStringFromRect([ tempView frame]) );
>> }
>>
>> }
>> }
>>
>>
>> On Nov 30, 2007, at 09:55, Joshua Emmons wrote:
>>
>>>> For some reason each time the resizeSubview method is called,
>>>> NSEnumerator alternately returns with either the first subview
>>>> in the array, or the last. The first time the method is called,
>>>> the first subview is number 0, continuing through 41. The next
>>>> time it goes through the array, the enumerator starts with
>>>> subview 41, skips subview 0, and iterates to subview 1, then 2,
>>>> 3 etc.
>>>
>>> I haven't come across this behavior before, and a quick sample
>>> app doesn't exhibit it. Maybe give some more details about your
>>> implementation? Maybe it's a bug with how your calling NSEnumerator?
>>>
>>> Cheers,
>>> -Joshua Emmons
>>
Have you tried avoiding the enumerator entirely and just using
another index var and objectAtIndex: to read the subDayViews array?
I'm having trouble believing that this is a problem with
NSEnumerator... I have a feeling your array is not what you expect.
In fact, if you haven't already, I'd try dumping the array's
description to the log.
The only other thing I can think of is that maybe you've got this
code in the class for the views that you're working on, and your call to
[ tempView setFrame: newRect ]
is causing your setFrameSize override to be called, which is calling
resizeDayViews again, giving you misleading log statements and
general chaos. In other words, are you sure you're not reentering the
method because of that setFrame call in the loop (or something else)?
I have no idea if setFrame causes the setFrameSize override to be
called, but it wouldn't surprise me. You may want to log entry and
exit for the method, or step through the loop in the debugger.
Anyway, just some late night thoughts that may or may not help.
- d
DATE : Sat Dec 01 07:21:32 2007
> On Nov 30, 2007, at 10:18, Vince Ackerman wrote:
>
>> Sorry, I was using Bounds instead of Frame... but it still
>> doesn't change the behavior with the array. Here are the two
>> methods I'm using:
>>
>> /* Changing frame (which is what happens when the window is
>> resized) should cause relayout.
>> */
>> - (void)setFrameSize:(NSSize)size {
>> [super setFrameSize:size];
>> [self resizeDayViews: size];
>> }
>>
>>
>> -(void)resizeDayViews: (NSSize) size // Adjust all subViews for
>> size of Main view
>> {
>> NSArray *subDayViews = [self subviews]; // get array of all
>> subviews
>> NSEnumerator *enumerator = [subDayViews objectEnumerator]; // get
>> enumerator to step through the subview array
>>
>> NSRect newFrame = [self frame]; // get current bounds rect
>> NSRect newRect;
>>
>>
>> float dayWidth = ( (newFrame.size.width - 9) / 7);
>> float weekHeight = ( (newFrame.size.height - 9) / 6) ;
>> int x,y,rowCnt, columnCnt;
>>
>> NSLog( @"Start of Resize Method------------------------------");
>>
>> // for each row of days
>> for (y = 5, rowCnt = 0; rowCnt < 6; y = y + weekHeight,
>> rowCnt++)
>> {
>> for(x = 5, columnCnt = 0; columnCnt < 7; x = x + dayWidth,
>> columnCnt++)
>> {
>> newRect = NSMakeRect(x, y, dayWidth, weekHeight );
>> DayView *tempView = [enumerator nextObject];
>> [ tempView setFrame: newRect ];
>> NSLog( @"frame set");
>> NSLog( @"%@", [NSString stringWithFormat:@"%i", [tempView
>> gridNum] ]);
>> NSLog(@"%@", NSStringFromRect(newRect) );
>>
>> NSLog(@"%@", NSStringFromRect([ tempView frame]) );
>> }
>>
>> }
>> }
>>
>>
>> On Nov 30, 2007, at 09:55, Joshua Emmons wrote:
>>
>>>> For some reason each time the resizeSubview method is called,
>>>> NSEnumerator alternately returns with either the first subview
>>>> in the array, or the last. The first time the method is called,
>>>> the first subview is number 0, continuing through 41. The next
>>>> time it goes through the array, the enumerator starts with
>>>> subview 41, skips subview 0, and iterates to subview 1, then 2,
>>>> 3 etc.
>>>
>>> I haven't come across this behavior before, and a quick sample
>>> app doesn't exhibit it. Maybe give some more details about your
>>> implementation? Maybe it's a bug with how your calling NSEnumerator?
>>>
>>> Cheers,
>>> -Joshua Emmons
>>
Have you tried avoiding the enumerator entirely and just using
another index var and objectAtIndex: to read the subDayViews array?
I'm having trouble believing that this is a problem with
NSEnumerator... I have a feeling your array is not what you expect.
In fact, if you haven't already, I'd try dumping the array's
description to the log.
The only other thing I can think of is that maybe you've got this
code in the class for the views that you're working on, and your call to
[ tempView setFrame: newRect ]
is causing your setFrameSize override to be called, which is calling
resizeDayViews again, giving you misleading log statements and
general chaos. In other words, are you sure you're not reentering the
method because of that setFrame call in the loop (or something else)?
I have no idea if setFrame causes the setFrameSize override to be
called, but it wouldn't surprise me. You may want to log entry and
exit for the method, or step through the loop in the debugger.
Anyway, just some late night thoughts that may or may not help.
- d






Cocoa mail archive

