I am trying to pass data to a uiview but it keeps showing up null

zzinzzin CAMember ✭✭
edited January 2018 in Xamarin.iOS

public override void ViewDidLoad()
{
base.ViewDidLoad();
hv = HomeView.Create();
uiview.Frame = hv.Frame;
uiview.AddSubview(hv);
hv.N = "text"; <---- data im trying to pass
}

public partial class HomeView : UIView
{
public HomeView (IntPtr handle) : base (handle)
{
}

    public static HomeView Create()
    {
        var arr = NSBundle.MainBundle.LoadNib("HomeView", null, null);
        var v = Runtime.GetNSObject<HomeView>(arr.ValueAt(0));
        return v;
    }
    public string N { get; set; }

    public override void AwakeFromNib()
    {
        balance.Text = N;<--- null
        //   MyLabel.Text = "hello from the SomeView class";
    }
}

Answers

  • andnesandnes USMember ✭✭✭
    edited January 2018

    My guess is it's because you're setting the property after you've added the view as a subview. Try changing the code to this:

    hv = HomeView.Create();
    hv.N = "text";
    uiview.Frame = hv.Frame;
    uiview.AddSubview(hv);
    

    If that doesn't work I'd try sending in the desired text as a parameter in the HomeView.Create() method, like this:

    public static HomeView Create(string text)
    {
        N = text;
        var arr = NSBundle.MainBundle.LoadNib("HomeView", null, null);
        var v = Runtime.GetNSObject<HomeView>(arr.ValueAt(0));
        return v;
    }
    
  • zzinzzin CAMember ✭✭

    @andnes yeah i tried both n still null & the second one can be done because it is a default parameter. thanks alot for ur suggestions tho

Sign In or Register to comment.