My team has recently converted a fairly large project to ARC. The conversion went well and the app runs, and works fine on 5.0.
The problem is on 4.3. Any view controllers instantiated in code with plain init do not load any subviews of the vc’s view (this does work on 5.0)
Here’s the summary:
Instantiate a view controller with [[MyViewController alloc] init]. (UIViewController’s init calls initWithNibName:nil bundle:nil)
This loads a nib with the same name as the View Controller (MyViewController.xib)
*Expected: the nib is instantiated normally with all subviews of top level view and all outlets set
*Actual: the nib is instantiated, and the MyViewController object’s view property is set. However, the view’s subviews array is empty and any outlets to these views are nil, and the view appears empty when presented
*Workaround: instantiate VC/load nib by using
[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]
I haven’t been able to replicate this in a clean project, either starting with ARC or converting to ARC. My team and I are working on this, but in the meantime, wondered if anyone else has run into this and found a root cause or trigger.
A follow up in case anyone else has this problem.
Since we are supporting 4.x and using ARC, we decided to use Mike Ash’s MAZeroingWeakRef to get a weak pointer in 4.x. Eventually we isolated the problem enough to trace it back to MAZeroingWeakRef. We posted an issue to the MAZWR project and github and Mike explained what was happening:
https://github.com/mikeash/MAZeroingWeakRef/issues/13
(Basically MAZWR changes the internal name of the VC class to something like TestViewController_MAZeroingWeakRefSubclass. The VC’s init depends on this class name to load its associated nib — so when it is changed it can’t find the nib. By calling initWithNibName:bundle: and explicitly supplying the class name the associated nib is loaded properly.)