Skip to content

Instantly share code, notes, and snippets.

@patridge
Created October 17, 2012 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patridge/3907891 to your computer and use it in GitHub Desktop.
Save patridge/3907891 to your computer and use it in GitHub Desktop.
Bug: Custom UITabBarController calling ViewDidLoad from base constructor.
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