简体   繁体   English

IPHONE-使用多个视图

[英]IPHONE - Use multiple views

I have to make an application with six views, which can be accessed to by bar button items on a toolbar. 我必须制作一个具有六个视图的应用程序,可以通过工具栏上的条形按钮项目进行访问。

I'm really new at this. 我真的很新。 I have a view controller and a XIB file for each view, with six functions (goToView1, goToView2, ..., goToView6). 我有一个视图控制器和每个视图的XIB文件,具有六个功能(goToView1,goToView2,...,goToView6)。

Here is an example : 这是一个例子:

SecondViewController *secondview;

-(IBAction)goToView2 {
    secondview = [[SecondViewController alloc] 
                 initWithNibName:@"SecondViewController" bundle:nil];
    [self.view addSubview:secondview.view];
}

But as you can see, if I want to go from view3 to view2, I'm not deleting the view3 from the stack : I'm just adding the view2 over it. 但是正如您所看到的,如果我想从view3转到view2,则不会从堆栈中删除view3:我只是在其上添加view2。 So here's my problem, how do I "delete" my view before using addSubView ? 所以这是我的问题,在使用addSubView之前如何“删除”视图? I tried with removeFromSuperView, but I think I'm not using it right. 我尝试使用removeFromSuperView,但我认为使用的方式不正确。

Thanks for helping, as I said I'm really new and I am aware it can be a stupid question :/ 感谢您的帮助,正如我所说的,我真的很新,我知道这可能是一个愚蠢的问题:/

It sounds very much like you want to use a UITabBarController , as this will provide the toolbar (with icons), etc. and will automatically handle displaying the appropriate view controller when a specific toolbar icon is selected. 听起来非常像您想要使用UITabBarController ,因为它将提供工具栏(带有图标)等,并且在选择特定的工具栏图标时将自动处理显示适当的视图控制器。

However, I'd really recommend first reading the View Controller Programming Guide for iOS document, as it provides a good overview of the various UIKit controllers, etc. and how they should be used. 但是,我真的建议您先阅读《 iOSView Controller编程指南》文档,因为它很好地概述了各种UIKit控制器等,以及如何使用它们。 If you take the time to read and understand this now, it'll serve you well in the future. 如果您现在花时间阅读和理解此内容,它将在将来为您服务。

Take a look at UITabBar. 看看UITabBar。 I think using a tab bar might be better suited for what you want to do, than a toolbar. 我认为使用标签栏可能比工具栏更适合您要执行的操作。

UITabBar Class Reference UITabBar类参考

to remove the fisrt view you should use something like this. 要删除fisrt视图,您应该使用类似这样的东西。

   [fisrtView removefromSuperview];

put in where you want to remove view. 放在您要删除视图的位置。

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

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