Call a new IOS class

2

I'm new to the IOS environment and after studying a bit how the language works, I did not understand how I can call a window / class and superimpose the current window as I do on android.

Intent intent = new Intent(a.class, b.class);
startActivity(intent);

I started an application with tab control and searching in the English stack and in some tutorials on the internet, I saw that it is necessary to use a navigation control. When I apply the navigation control in the view, I use the code below to open the new class.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:@"Dicas"];
[self.navigationController pushViewController: myController animated:YES];

It works, but it just changes the current view to the new one ... just like the image below.

Is there any way to call a new window without being this way and without using navigation control? Because I'm using tabs at the bottom it would make something strange a navigation control at the top.

    
asked by anonymous 01.08.2014 / 14:34

2 answers

1

The navigation of this app is not strange, on the contrary, this type of behavior is very common in iOS apps. However, you are not required to place instances of UINavigationController as children of the TabBar. Example:

UIViewController* controller = [UIViewController new];
[controller setTitle:@"Controller 1"];
UINavigationController *navController = [UINavigationController new];
[navController setTitle:@"Tab 1"];
[navController setViewControllers:@[controller]];

UIViewController* controller2 = [UIViewController new];
[controller2 setTitle:@"Controller 2"];

UITabBarController *tabBarController = [UITabBarController new];
[tabBarController setViewControllers:@[navController, controller2]];
[self.window setRootViewController:tabBarController];

In this example I created a tab bar with two children: the first is a UINavigationController , the second a UIViewController .

In addition to pushViewController to UINavigationController as you used, there are other recurring ways to add a view controller in the hierarchy. You can use presentViewController which will add a controller over the entire screen:

UIViewController *detailController = [UIViewController new];
[controller2.tabBarController presentViewController:detailController animated:YES completion:nil];

If you need to add a controller with a specific size, in any part of the current controller view, just like a button, for example, the View Controller Containment concept is used. This concept is similar to that of Android Fragments.

UIViewController *detailController = [UIViewController new];
detailController.view.backgroundColor = [UIColor redColor];
CGRect frame = CGRectMake(100, 100, 200, 200);
[detailController.view setFrame:frame];
[controller2 addChildViewController:detailController];
[controller2.view addSubview:detailController.view];
[detailController didMoveToParentViewController:controller2];

In addition to the code to add the view of the new controller in a view of the current controller, you need to tell the parent / child relationship to both. This will allow the child controller to receive the life cycle callbacks from the parent controller's view.

    
01.08.2014 / 16:36
1

You can give a presentViewController that view will come from the bottom up without doing the navigation.

    
11.08.2014 / 20:44