Reputation: 7674
Lets say I have 4 screens (iPhone view controllers) in my App, and I like to navigate between them. For example:
> 1 ----> 2
> 2 ----> 3
> 3 ----> 2 (With new data)
> 2 ----> 4
> 4 ----> 1
This is off course just an example, what is the correct way to achieve that?
Upvotes: 0
Views: 259
Reputation: 33428
Udi I,
the correct way to achieve such type of navigation is through UINavigationController
. From Apple documentation:
The
UINavigationController
class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and also makes it easier for the user to navigate that content. This class is generally used as-is but may be subclassed in iOS 6 and later.
The following APIs allow you to navigate in the stack
– pushViewController:animated:
– popViewControllerAnimated:
– popToRootViewControllerAnimated:
– popToViewController:animated:
If you need to pass data between controllers, just inject them like the following:
// within the third controller
UIViewController* secondController = // new controller
secondController.dataToInject = // ...
[self.navigationController pushViewController:secondController animated:YES];
where dataToInject
could be defined in SecondController
as
@property (nonatomic, retain) id dataToInject;
Hope that helps.
P.S. The code is written in objective-c but with small modifications is valid also for MonoTouch.
Use this
instead of self
, for example.
Upvotes: 1