Forum Xamarin Xamarin.iOS

Lamda expression and closure

lufo88lufo88 USMember ✭✭✭

in my iOS app I use often these lines of code in ViewDidLoad:

var backButton = new UIBarButtonItem (UIImage.FromBundle ("ic_close"), UIBarButtonItemStyle.Plain, (sender, args) => NavigationController.PopViewController (true));
NavigationItem.SetLeftBarButtonItems (new [] { backButton }, false);

I do this in order to override the default back button in iOS. However, sometimes the app crash because NavigationController in the lambda expression is null.

The custom UIViewController I use is created always in the same way, so I do not understand why the NavigationController is null.

Sign In or Register to comment.