Autoresizes Subviews setting changes randomly when loading NIB

Originator:jlieske
Number:rdar://8179031 Date Originated:11 July 2010
Status:Open Resolved:
Product:Mac OS X Product Version:10.6.4 10F569
Classification:UI/Usability Reproducible:Sometimes
 
Summary:

When a Cocoa app loads a NIB with a custom view, the resizesSubviews property on that view is changed randomly when the NIB loads.

Steps to Reproduce:

Create a simple Cocoa app in Xcode 3.2.2.

Add a custom view class.  In that class:
* perform self.autoresizesSubviews = NO in -[initWithFrame:]
* add an override of -[setAutoresizesSubviews:] that logs its argument to the console
* add an override of awakeFromNib that sets a string in the UI (e.g. the window title) to the value of self.autoresizesSubviews

Add the following view hierarchy to the window displayed by the application:
* Window
** Content View -- make it scale in all directions, fixed margins
*** Custom View -- set the class to the custom view class; make it scale in all directions, fixed margins; set Autoresizes Subviews to off
**** Box -- make it scale in all directions, fixed margins
***** arbitrary child views of the box

Build the app.
Run the app either from Xcode or from the Finder.

See the attached project for an example.

Expected Results:

* The console log will show only one call to setAutoresizesSubviews -- the one call from -[initWithFrame:]

* The UI for the app will show the value NO for autoresizesSubviews

* The box will not change shape as the window resizes

Actual Results:

Randomly, the app will show the below behavior:

* The console log has two calls to setAutoresizesSubviews, first with NO, then with YES

* The UI for the app will show the value YES for autoresizesSubviews

* The box changes shape in sync with window resizing

At other random launches, the app will show the expected behavior.

Regression:

Almost the same behavior on Power Mac G5 running 10.5.7, using the executable build under 10.6.4.  On that system, loading the NIB always changes autoresizesSubviews to YES, whereas on an iMac running 10.6.4, the value is random.

Comments

Code for custom class

Since Open Radar doesn't let me attach a ZIP of the project, here's the custom class code from my bug report.

@implementation AutoresizesSubviewsDemo

  • (id) initWithFrame: (NSRect) frame { self = [super initWithFrame: frame]; if (self) { self.autoresizesSubviews = NO; } return self; }

  • (void) setAutoresizesSubviews: (BOOL) flag { NSLog(@"%@ autoresizesSubviews = %s", self, flag ? "YES" : "NO"); [super setAutoresizesSubviews: flag]; }

  • (void) resizeSubviewsWithOldSize: (NSSize) oldBoundsSize { NSLog(@"%@ resizeSubviewsWithOldSize: %f×%f", self, oldBoundsSize.width, oldBoundsSize.height); [super resizeSubviewsWithOldSize: oldBoundsSize]; }

  • (void) awakeFromNib { BOOL autoresizes = self.autoresizesSubviews; self.window.title = [NSString stringWithFormat: @"AutoresizesSubviews = %s", autoresizes ? "YES" : "NO"]; }

@end


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!