Reputation: 133
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:
Upvotes: 1
Views: 964
Reputation: 133
Answer my questions reading posts and discussions on this links:
Initialization Data after it receiving from another ViewController
https://chat.stackoverflow.com/rooms/100060/discussion-between-dylan-s-and-artem-shcherbakov
Upvotes: 0
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