Artem  Shcherbakov
Artem Shcherbakov

Reputation: 133

How send data from View Controller to View Controller Xamarin iOS(C#)

I'm have some view with some button(name - 'button_arrow_product002'), I'm want send data wen button 'button_arrow_product002' be clicked My code in ViewController name 'HarachieRolliController':

String title = json[1]["post_title"].ToString();
button_arrow_product002.TouchUpInside += (o,s) => {         
        DetailTovarProsmotr x;
        x.HendlerButtonClicked(title);
        Console.Out.WriteLine("Нажали кнопку перехода в детальный просмотр!!!!");
};

code ViewCotroller what handle button clicked:

namespace murakami_kiev
{
partial class DetailTovarProsmotr : UIViewController
{

    public DetailTovarProsmotr (IntPtr handle) : base (handle)
    {
    }
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

    }
    public void HendlerButtonClicked(String json){
        titleproduct.Text = json;

    }
}
}

in this code I'm have error

'Use of unassigned local variable'

When I'm create 'new DetailTovarProsmotr()' I'm mast have some arguments but I'm don't know those.

UPDATE

I'm create second constructor and receive String type variable. But I'm have error 'Object reference not set to an instance of an object'.Help me with my problem. My screenshot:enter image description here

Upvotes: 1

Views: 964

Answers (2)

tequila slammer
tequila slammer

Reputation: 2879

As a summery. The root of all your exceptions are that you are trying to access/ set a member of a not instantiated class.

As I mentioned in the comments already you need to create an instance and then you can modify it.

To fix your first problem you need to change DetailTovarProsmotr x; to DetailTovarProsmotr x = new DetailTovarProsmotr(); and create a standard constructor in DetailTovarProsmotr controller.

The same applies basically to your second problem with titleproduct. titleproduct is of type UITextView so you need to create an instance you can then operate on by setting the text property. Add titleproduct = new UITextView(new CGRect(10,10,120,30)); before titleproduct.Text = title2; will solve your NullReferenceException.

Upvotes: 1

Related Questions