Created
October 17, 2012 20:18
-
-
Save patridge/3907891 to your computer and use it in GitHub Desktop.
Bug: Custom UITabBarController calling ViewDidLoad from base constructor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
namespace TabBarFailTest { | |
public class Application { | |
static void Main(string[] args) { | |
try { | |
UIApplication.Main(args, null, "AppDelegate"); | |
} | |
catch (Exception ex) { | |
Console.WriteLine("Top-level exception: {0}", ex); | |
} | |
} | |
} | |
[Register ("AppDelegate")] | |
public partial class AppDelegate : UIApplicationDelegate { | |
UIWindow window; | |
FailingTabBarController failingTabBarController; | |
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { | |
window = new UIWindow(UIScreen.MainScreen.Bounds); | |
SomeClass something = new SomeClass(); | |
failingTabBarController = new FailingTabBarController(something) { | |
ViewControllers = new [] { | |
new UIViewController() { TabBarItem = new UITabBarItem(UITabBarSystemItem.Favorites, 0) } | |
} | |
}; | |
window.RootViewController = failingTabBarController; | |
window.MakeKeyAndVisible(); | |
return true; | |
} | |
} | |
public class SomeClass { | |
public string SomeProperty = "test1"; | |
public string SomeOtherProperty = "test2"; | |
} | |
public class FailingTabBarController : UITabBarController { | |
public SomeClass Something { get; set; } | |
public FailingTabBarController(SomeClass something) { | |
this.Something = something; | |
} | |
public override void ViewDidLoad() { | |
base.ViewDidLoad(); | |
// Throws null exception because base UITabBarController constructor | |
// calls this method directly (before the inheriting class constructor | |
// is called to set properties). | |
this.Title = Something.SomeProperty; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment