How to launch a new screen in iOS?

This is a very simple question, but I do not know how to do it.

The first thing I discovered is that I have to add a navigation controller. Although I do not need to show the navigation controller, I tried. I found these tutorials: http://www.ralfebert.de/tutorials/iosdev/navigationcontroller/

http://www.techotopia.com/index.php/Creating_a_Navigation_based_iOS_4_iPhone_Application_using_TableViews

http://iosmadesimple.blogspot.de/2012/09/navigation-based-project-doing-it-using.html

and others, where it says, I have to connect the navigation controller to the window object. But there is no window object in .xib. It seems like some updates, I found that the window object created programmatically in AppDelegate.m

Does this mean that I should connect them programmatically, if so, how?

I am using Xcode 4.4.1 for 5.1.

Then I found a hacker approach to replace the views discussed here: http://fuelyourcoding.com/ios-basics-how-to-load-a-uiview-without-a-navigation-controller/

But I want to know that this is the standard way to do this.

The Apple dev manual has something about storyboards. This is what I need?

I need to know how I launch a separate new screen (with my own controller and .xib, of course), if possible, without the need to add a navigation bar to the application.

+4
source share
3 answers

The best way to do this is to use a navigation controller.

In the AppDelegateWillFinishLaunchingWithOptions app, enter this ...

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:<the view controller you want to use first>]; self.window.rootViewController = self.navController; [self.window makeKeyAndVisible]; 

This will launch your application using the NavigationController, and the first thing you see will be your initial controller.

To hide the panel ...

In the viewWillAppear part of your initial view controller ...

 [self.navigationController setNavigationBarHidden:YES animated:YES]; 

This will hide the navigation bar for this controller.

To go to the new view controller ...

 MyNewViewController *newVc = [[MyNewViewController... (set it up). [self.navigationController pushViewController:newVc animated:YES]; 

This is done using the initial view controller.

Then jump back. In the new VC, just do it ...

 [self.navigationController popViewControllerAnimated:YES]; 

You will never own the navigation controller and you will never see it. It just sits at your application, managing transitions, etc.

+4
source

You can show a modal view if you do not want to use the NavigationController. In this SO question, you can find how to do this: Submit and reject the modal view controller

The presentation of the view using the NavigationController is either independent of the purpose of that view, and it is related to the flow of your screens. If you need to “drill” into a series of UITableViews or simply navigate through various screens before you reach a certain one, you must use the UINavigationController to process it. Take a look at http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

I personally prefer to use StoryBoards for applications with a lot of views, because it helps me to have a clear "picture" of their hierarchy, as well as the relationship between them.

In the end, it's just a matter of taste. If you want to know more about StoryBoards, I recommend you this entry: http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

If you want to learn how to create a modal view using StoryBoards, the easiest way to show it is to create a new project by selecting the "Application with one view" option and checking the "Use storyboards" option in the next screen. After that, you should select the file "MainStoryboard.storyboard" inside the project folder in Xcode. Then drag “Controller View” (the first orange circle with a square on it) from the lower right corner and drop it into your StoryBoard, next to the one that has already been created.

You should now have two different ViewControllers. Just drag the UIButton from the lower right corner (you need to scroll to see the "Round Rect Button" parameter) for the first ViewController (the one with the arrow pointing to it on the left).

And finally, you need to hold Control + Click on this UIButton and associate this button with another ViewController. After that, you will see the "Segue Action" dialog. Just choose Modal and voila!

Here's what your StoryBoard looks like:

modal view controller

Note I changed the color of the second ViewController to make it more obvious.

I recommend that you read the raywenderlich tutorial first and then do your modal presentation by following these steps.

+1
source
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. YourViewController *viewController = [[YourViewController alloc] init]; navController = [[UINavigationController alloc] initWithRootViewController:viewController]; // Add the view controller view to the window and display. [window addSubview:navController.view]; [window makeKeyAndVisible]; return YES; } 
0
source

Source: https://habr.com/ru/post/1446758/


All Articles