Reputation: 2660
So Im rewriting an App that I have previously previously written in objective-c. In objective-c I would store the data(5 array's) in separate NSUserdefaults and then call them in the new ViewController.
Since I started programming in MonoTouch this feels kinda wrong. Im also now using shared code for this and created a class that is fetching the data. Let me explain how the flow of my app works:
So what would be the best way to tackle this?
Upvotes: 4
Views: 4362
Reputation: 4625
Subclass the ViewController, adding some new parameter(s) on it's constructor for the data, so that you can pass the data to the controller when you display it.
public class MyViewController : UIViewController
{
private MyData _myData;
public MyViewController(MyData myData)
{
_myData = myData;
}
}
Then use it:
(assuming we're already in another view controller that has a NavigationController):
var myViewController = new MyViewController(myData);
this.NavigationController.PushViewController(myViewController, true);
or (as a "modal")
var myViewController = new MyViewController(myData);
this.PresentViewController(myViewController, true);
Upvotes: 2