/ / ¿Cómo obtener la barra de navegación en el controlador de vista? - iOS, Objective-C, iPhone, uitableview

¿Cómo obtener la barra de navegación en ver controlador? - ios, object-c, iphone, uitableview

Tengo tres controladores de vista A B CTengo un controlador de navegación conectado a UN ver controlador. UN Tengo algunos botones, he adjuntado el botón a segundo ver controlador. Al hacer clic en el botón voy a la segundo ver controlador. segundo Ver controlador que tengo UITableView al hacer clic en el elemento de vista de tabla, estoy lanzando el do view controller.below es el código para eso

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0)
{
NSLog(@"first cell");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"BusinessCard"];
[self presentViewController:vc animated:YES completion:nil];

}
else if(indexPath.row==1)
{
NSLog(@"second cell");


}
else if(indexPath.row==2)
{
NSLog(@"third cell");

}

}

Pero en do No aparece la barra de navegación. Creo que el controlador de vista C no está vinculado al controlador de navegación.

Respuestas

2 para la respuesta № 1

Tu usas navigationController Método push para mostrar la barra de navegación en C viewController

prueba este código:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"BusinessCard"];
[self.navigationController pushViewController:vc animated:YES];

1 para la respuesta № 2

Usa el código de abajo

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"BusinessCard"];
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:nil];

Necesitas presentarlo usando UINavigationController como modal.

Espero eso ayude.


1 para la respuesta № 3

utilizar esta:

 [self.navigationController pushViewController:vc animated:YES];

0 para la respuesta № 4

Puede usar "Push" segue e incrustar su ViewController en el Controlador de navegación, y luego usar las funciones de su Controlador de navegación como pushViewController y popViewControllerAnimated


0 para la respuesta № 5

Las respuestas son correctas, pero solo quiero explicar las cosas ...

//This line gets the storyboard with the name "Main" which contains all
//the setup you made for UI (User interface)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];

//While this like gets the view inside your storyboard with
//storyboard ID/indentifier `BusinessCard `
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"BusinessCard"];

//Lastly, this line is correct presenting the viewcontroller BUT this doesn"t add your
//viewcontroller to the array of viewControllers inside navigationController
//
//Also, this line makes you present the viewController above the
//rootViewController of window which is in your case the navigationController
//
This is you Error
[self presentViewController:vc animated:YES completion:nil];

//This is what you are looking for, and the correct one for your implementation
//
//This will let you add the `vc`(viewController) to the array of viewController
//in navigationController, to confirm that you can check the `self.navigationController.viewControllers`
//which will return the array of viewController inside your navigationController
This is the Answer
[self.navigationController pushViewController:vc animated:YES];

Espero que esto te ayude, y mi explicación es aprensible. Saludos