Teddy13
Teddy13

Reputation: 3854

switching views without navigation controller

I have a tab controller and within this tab controller one of the views is called random. Within random, I have added multiple views (without making new .xib files or .m/.h) that I simply create in interface builder and linkup. For example, I created landscape view. I have a button within the original view (random) that takes me to landscape view with a simple line of code: self.view=landscape;. This works. My problem is having a custom "back" button that will take me to the original view. I tried calling self.view=view; but this did not work. When I check the connection in interface builder with the original view, it simple just says "view". What line of code is needed to return me to the original view ("view")?

Thank you in advance and my apology if this is extremely obvious

Upvotes: 0

Views: 408

Answers (1)

Clafou
Clafou

Reputation: 15400

I guess you could persist your original view so that you can restore it later. This should do it:

Add this property to your view controller (in your .h header file):

@property (nonatomic, retain) IBOutlet UIView *originalView;

Autogenerate the accessors (in your .m implementation file):

@synthetize originalView

Inside your viewDidLoad method, assign the actual original view from the NIB to it:

self.originalView = self.view

And then to return to your original view after a click on your back button, do this:

self.view = self.originalView

Upvotes: 1

Related Questions