简体   繁体   English

在没有导航控制器的情况下切换视图

[英]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. 在随机范围内,我添加了多个视图(无需创建新的.xib文件或.m / .h),这些视图只是在界面生成器和链接中创建的。 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;. 我在原始视图(随机)中有一个按钮,通过简单的代码行即可将我带到风景视图: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; 我试图打电话给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): 将此属性添加到视图控制器(在.h头文件中):

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

Autogenerate the accessors (in your .m implementation file): 自动生成访问器(在您的.m实现文件中):

@synthetize originalView

Inside your viewDidLoad method, assign the actual original view from the NIB to it: 在viewDidLoad方法中,将来自NIB的实际原始视图分配给它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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