Skip navigation.
 
mlRe: Creating subviews programmatically ?
FROM : Vince Ackerman
DATE : Sat Dec 01 18:24:59 2007

As per your suggestion I've Eliminated the NSEnumerator, and using 
NSArray objectAtIndex: index  shows the same behavior. Aside from 
sending an "addSubview" to the view in my awakeFromNib, and building 
the original grid of subviews, I'm not messing with the subviews 
anywhere else but the resize method.

The first and last subview in the array are switched each time 
through.  This are my two methods:

- (void)setFrameSize:(NSSize)size {
   NSLog(@"Override setFrameSize called");
    [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
   NSRect newFrame = [self frame];            // get current frame rect
   NSRect newRect;
   float dayWidth = ( (newFrame.size.width - 9) / 7);
   float weekHeight = ( (newFrame.size.height - 9) / 6) ;
   int x,y,rowCnt, columnCnt, index;
   
   NSLog( @"Start of Resize Method------------------------------");
   NSLog( [subDayViews description]);
   // for each row of days
   for (index = 0, 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 = [subDayViews objectAtIndex: index];
           [ tempView setFrame: newRect ];
           NSLog( @"frame set");
           NSLog( @"%@", [NSString stringWithFormat:@"%i", [tempView 
gridNum] ]);
           NSLog(@"%@", NSStringFromRect(newRect) );
           index++;
       }
       
   }
}



On Nov 30, 2007, at 22:21, Dave Hersey wrote:
>
>
> 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

Related mailsAuthorDate
mlCreating subviews programmatically ? Vince Ackerman Nov 26, 17:18
mlRe: Creating subviews programmatically ? j o a r Nov 26, 17:27
mlRe: Creating subviews programmatically ? I. Savant Nov 26, 17:31
mlRe: Creating subviews programmatically ? Vince Ackerman Nov 26, 17:59
mlRe: Creating subviews programmatically ? Erik Buck Nov 26, 20:59
mlRe: Creating subviews programmatically ? I. Savant Nov 26, 21:35
mlRe: Creating subviews programmatically ? Scott Anguish Nov 27, 02:16
mlRe: Creating subviews programmatically ? Ricky Sharp Nov 27, 02:55
mlRe: Creating subviews programmatically ? I. Savant Nov 27, 02:57
mlRe: Creating subviews programmatically ? Vince Ackerman Nov 27, 16:32
mlRe: Creating subviews programmatically ? Vince Ackerman Nov 30, 18:49
mlRe: Creating subviews programmatically ? Vince Ackerman Nov 30, 18:54
mlRe: Creating subviews programmatically ? Vince Ackerman Nov 30, 19:04
mlRe: Creating subviews programmatically ? Vince Ackerman Nov 30, 19:18
mlRe: Creating subviews programmatically ? Vince Ackerman Dec 1, 06:46
mlRe: Creating subviews programmatically ? Dave Hersey Dec 1, 07:21
mlRe: Creating subviews programmatically ? Vince Ackerman Dec 1, 17:51
mlRe: Creating subviews programmatically ? Dave Hersey Dec 1, 18:22
mlRe: Creating subviews programmatically ? Vince Ackerman Dec 1, 18:24
mlRe: Creating subviews programmatically ? Vince Ackerman Dec 1, 18:59
mlRe: Creating subviews programmatically ? Vince Ackerman Dec 2, 13:35
mlRe: Creating subviews programmatically ? Scott Ribe Dec 4, 23:47