How make static view on any viewcontroller in Xcode?

雨燕双飞 提交于 2020-01-06 07:01:55

问题


I Have interesting question. I have two screens, I need that would be the third screen elements (buttons, label) are static and do not change when you move from one screen to another. . So MAIN DISPLAY 1 will be change, DISPLAY 2 too , but button and others(label for example) need be static.

Big Thanks for all help, sorry i don't have any code with this problem. Because i don't know how this make...


回答1:


Ok, so if you have a UI that won't change it's content you have to consider the following:

If the user can navigate from one screen to another, then you will have to create multiple view controllers(it can be done in other ways but this is the easiest and best way to doit) that will have their own UI, that can be easily created in storyboards like this:

Create a new project that use storyboars (you can use the Xcode templates that support your needs)

In your generated storyboard, drag and drop a new UINavigationController, and in the Attributes inspector check the Is initial view controller

Drag another UIViewController into your storyboard, select your navigation controller, hold right click and drag to the newly added view controller, a popup will appear and from that popup select root view controller. Now the newly added view controller will be the first view that the app will display. On this view controller add your UI elements (buttons, labels, etc). If you want another screen to be shown when a user taps on a button, drag another view controller and select the button from which you want to display the next screen, hold right click drag to the newly added view controller, from the popup select push. Now when the user tap on the button the next view controller will be shown and as a bonus because you use iOS, the system will create a back button so that you can go back to your first view controller.

Ok, this is the a basic tutorial from which you can start and expand, but for that you will have to read more, spend nights on google/SO to find solutions, you will learn apple docs by heart and other things that are required so that you can be a great iOS developer.

My the iOS force be with you and Steve Jobs watch your steps.




回答2:


This is off the top of my head: you could put a view into your uiwindow and place your static elements there, and then give a transparent background to display1 and display2. then you can have the two displays forward their touches to the background elements to have actions on the buttons. im sorry i dont have any code, but i never tried that ;)




回答3:


A much better way is to instantiate your ViewController like so:

this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);

Then inside your instantiated View Controller you setup a static variable that holds that instance of the View Controller:

public static StaticViewController staticViewController;

When the Static View Controller fires up for the first time:

staticViewController = this;

Now in the future when you fire up the Static View Controller (from wherever in your app) you can check to see if the StaticViewController.staticViewController variable is null or not.

Use simple if else logic to load it up accordingly:

if (StaticViewController.staticViewController == null) {
                StaticViewController.staticViewController staticViewController = this.Storyboard.InstantiateViewController ("StaticViewController") as StaticViewController;
                this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
            } else {
                if(!StaticViewController.staticViewController.IsBeingPresented) //safeguard against click happy users
                    this.NavigationController.PresentModalViewController (StaticViewController.staticViewController, true);
            }



回答4:


You should add the static views to your UINavigationController or whatever controller you are using for managing multiple controllers.



来源:https://stackoverflow.com/questions/16596623/how-make-static-view-on-any-viewcontroller-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!