Call a new IOS class

Asked

Viewed 181 times

2

I’m new in IOS environment and after studying a little how the language works, I did not understand how I can call a window/ class and overlap the current window as I do on android.

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

I started an application with tabs control and searching the English stack and some tutorials on the internet, I saw that it is necessary to use a navigation control. When applying navigational control to 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 more it just changes the current view to the new one.. being the same as the image below. inserir a descrição da imagem aqui

Is there any way to call a new window without this mode and without using navigational control? Because I’m using tabs at the bottom would look something strange a navigational control at the top.

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 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 one UIViewController.

Besides pushViewController in a UINavigationController as you used, there are other recurring ways to add a view controller to the hierarchy. You can use presentViewController that 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 of specific size, in any part of the current controller view, as you would with a button for example, you use the concept of View Controller Containment. This concept is similar to Fragments of Android.

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 new controller view in a current controller view, it is necessary to inform both parent/child relationship. This will allow the child controller to receive life cycle callbacks from the parent controller view.

1

You can give a presentViewController that the view will come from bottom to top, without navigating.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.