Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Updating UILabel

$
0
0

Hi guys, new to Xamarin and iOS so this may be a silly question:

Basically, I have a UITabBarController, NewGameScreen.cs (with NewGameScreen.designer.cs and NewGameScreen.xib) and as one of the tabs, I have StatsScreen.cs (with StatsScreen.designer.cs and StatsScreen.xib). StatsScreen has some labels that I want to modify from NewGameScreen, so I created a new StatsScreen object:

StatsScreen stats = new StatsScreen ();

Then I call a method as such:

stats.setStats (day, debt, money, bank, health, location); // All of the parameters here are local variables

The method looks like this:

public void setStats (int day, long debt, long money, long bank, int health, string location)
{
    LabelDay.Text = day.ToString ();
    LabelDebt.Text = debt.ToString ();
    LabelMoney.Text = money.ToString ();
    LabelBank.Text = bank.ToString ();
    LabelHealth.Text = health.ToString ();
    LabelLocation.Text = location;
}

When I run and click, I get:

A System.NullReferenceException was thrown. Object reference not set to an instance of an object.

I have tried changing things around, calling different sequences of methods, but I seem to only be able to call setStats from within the class that it resides, StatsScreen.

I must be making a fatal error, it shouldn't be difficult to update a UILabel like this.

Thanks for any help. :)


Viewing all articles
Browse latest Browse all 204402

Trending Articles