Xib designer uses obsolete SetNativeField/GetNativeField method but i don't know what I should use

Platform: Visual studio 2017
Target: iPad 10.3

We have a Xib with the following code

[Foundation.Connect("btnCubicmeterFactor")]
private UIKit.UIButton btnCubicmeterFactor {
get {
this.__mt_btnCubicmeterFactor = ((UIKit.UIButton)(this.GetNativeField("btnCubicmeterFactor")));
return this.__mt_btnCubicmeterFactor;
}
set {
this.__mt_btnCubicmeterFactor = value;
this.SetNativeField("btnCubicmeterFactor", value);
}
}

On building the project we get a warning:
warning CS0618: 'NSObject.SetNativeField(string, NSObject)' is obsolete: 'Do not use; this API does not properly retain/release existing/new values, so leaks and/or crashes may occur.'

When running the application on the iPad crashes do occur. I would love to fix the warning, but i can not find any documentation on how to resolve this issue. The docs at https://developer.xamarin.com/api/namespace/MonoTouch.Foundation/ says so, but no direction on how to resolve.
Has anyone experienced similar problems and or now how to resolve these warnings?

we use these xib to add the control at runtime.

Kind regards,
Rim

Best Answer

  • Accepted Answer
    Hi @descorp
    Tnx for your replies. It is code from a project which originally started in 2009. At the time these gui options where not available. We fixed the issue by removing the code and let them be generated again.

    Kind regards,
    Rim

Answers

  • descorpdescorp RUUniversity ✭✭

    Hi @RanshuijsenVanLoon

    XIB is a XML format. I believe you have problem in code behind of XIB..
    Check this Xamarin API it require for manual mapping.

    In most cases you don't need to do it manually - just create new View from Add New > New File dialog and work in iOS Designer or Xcode Interface Builder

  • descorpdescorp RUUniversity ✭✭

    we use these xib to add the control at runtime.

    Sorry I missed this part.

    Why you do this ?
    Why no just add Button as a subview ?

  • RanshuijsenVanLoonRanshuijsenVanLoon NLMember
    Accepted Answer
    Hi @descorp
    Tnx for your replies. It is code from a project which originally started in 2009. At the time these gui options where not available. We fixed the issue by removing the code and let them be generated again.

    Kind regards,
    Rim
Sign In or Register to comment.