简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM