dimko1
dimko1

Reputation: 872

Xamarin template views

So, today I've used this recipe from Xamarin ( http://docs.xamarin.com/recipes/ios/general/templates ). It was created as i was expecting - but when i try to create button event handler in template constructor I receive exception that button is null (outlets are created and available form the code). Source code of this recipe is not available form Xamarin web site.
One more interesting observation - if I add textinput into this template, when I show this UIView - i see it, but touches to this control are not handled ( even standard one, like focus ).

Any ideas what can be wrong?

Upvotes: 1

Views: 443

Answers (1)

Stephane Delcroix
Stephane Delcroix

Reputation: 16232

Do not connect event handler in constructors, but in the ViewDidLoad() method.

At construction time, all your views (labels, buttons) aren't correctly instanciated yet, this happens a bit later. As a rule of thumb, don't create your Layout in your ctor, but do that in ViewDidLoad() and you should be fine.

Upvotes: 1

Related Questions