Bug 2700 - UITabBarController's base constructor calls loadView and viewDidLoad before constructor
Summary: UITabBarController's base constructor calls loadView and viewDidLoad before c...
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-12-30 11:16 UTC by Brian
Modified: 2013-10-07 07:56 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Brian 2011-12-30 11:16:59 UTC
During runtime loadView and viewDidLoad are called before UITabBarController's constructor.  This causes issues with wanting code that isn't re-run every time a view comes into view (right now the alternative is to throw the code into a *appear member).
Comment 1 Miguel de Icaza [MSFT] 2012-02-18 23:00:54 UTC
Hello Brian,

Do you have a test case that shows this?

I suspect the problem is that the constructor that is being called is a different constructor than the one you provided.
Comment 2 Adam Patridge 2012-10-17 16:21:35 UTC
I just ran into this problem as well. Here is a distilled sample that reproduces the problem.


Since the base UITabBarController..ctor is calling ViewDidLoad directly, the inheriting class' constructor code is never reached. In my real-world case, this means I cannot inject any dependencies into my custom TabBarController's constructor because they will all be null when ViewDidLoad executes.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-10-17 17:12:09 UTC
The native UITabBarController calls ViewDidLoad in its init method:

#23 0x00228ef8 in FailingTabBarController:ViewDidLoad ()
#24 0x0235192a in -[UITabBarController initWithNibName:bundle:] ()
#25 0x02338cf1 in -[UIViewController init] ()

I'm not sure we can actually do something about this.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2012-10-17 17:14:30 UTC
Comment 5 James Wilson 2012-10-28 19:05:41 UTC
I am having the same issue.  I am trying to pass a note class into the constructor as a dependency, but this is never touched when stepping through the code.  Any suggestions?
Comment 6 James Wilson 2012-10-28 19:32:45 UTC
Hi All, using the "view will appear" method solved the problem for me.

public override void ViewWillAppear (bool animated)
	base.ViewWillAppear (animated);
        //Utilize my dependency injection here
Comment 7 Rolf Bjarne Kvinge [MSFT] 2013-10-07 07:56:19 UTC
This usually happens when in a base class you call a virtual property, which ends up calling a virtual member on the derived class.

This is easy to see if you get a stack trace in the virtual method (such as ViewDidLoad) in the derived class, in which case you'll easily see what's happening.