I don't know if it can be a bug on MonoTouch, but I made a workaround with
InvokeMember, getting the control by name with reflectionŠ

Karl

From:  Karl Heinz Brehme Arredondo <[email protected]>
Date:  Wed, 23 Nov 2011 22:58:31 -0200
To:  "[email protected]" <[email protected]>
Subject:  [MonoTouch] GetNativeField don't get some controls anymore

Hi,

I have a method that use GetNativeField to get the instance of a control to
make dinamic manipulaton of text and other things from database, like
localization. So each view that is open it changes things to the user.

But, some ViewControllers was converted to the new "template" of MonoTouch
2.8 x Xcode 4 like:

[Outlet]

MonoTouch.UIKit.UINavigationBar lblTitle { get; set; }



[Outlet]

MonoTouch.UIKit.UIBarButtonItem menuItemBack { get; set; }


And now all UINAvigationBar and UiBarButtonItem aren't recognized anymore. A
Null is returned by GetNativeField. All ViewControllers in project that are
still on the old fashioned "template" are ok, like:

[MonoTouch.Foundation.Connect("lblTitle")]

private MonoTouch.UIKit.UINavigationItem lblTitle {

get {

this.__mt_lblTitle =
((MonoTouch.UIKit.UINavigationItem)(this.GetNativeField("lblTitle")));

return this.__mt_lblTitle;

}

set {

this.__mt_lblTitle = value;

this.SetNativeField("lblTitulo", value);

}

}


[MonoTouch.Foundation.Connect("menuItemBack")]

private MonoTouch.UIKit.UIBarButtonItem menuItemBack {

get {

this.__mt_menuItemBack =
((MonoTouch.UIKit.UIBarButtonItem)(this.GetNativeField("menuItemBack")));

return this.__mt_menuItemBack;

}

set {

this.__mt_menuItemBack = value;

this.SetNativeField("menuItemBack", value);

}

}


So, to test, I edit on Interface Builder an old ViewController, to make
MonoDevelop to change the code to the new template and GetNativeField stop
to find. Is there a better or new way to get a control from it's name? All
other things on screen are OK to find, like buttons and labels.

Thanks,

Karl
_______________________________________________ MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to