Pregunta

tabBarController = [[UITabBarController alloc] init];   //Create a tab bar  
view1 = [[View1 alloc] init];   //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
view2 = [[View2 alloc] init];   //create the second view
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:view2];
navigationController2.navigationBar.tintColor =[UIColor blackColor];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController1, navigationController2,nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

El código anterior son de mi clase AppDelegate (applicationDidFinishLaunching). View1 y Vista2 son UIViewController. Esta es la forma en que originalmente diseñar mis aplicaciones, las aplicaciones que tiene dos pestañas, (view1 y view2). El código a continuación, poner en práctica lo que sucede en View1, cuando el usuario desliza el dedo hacia la izquierda o la derecha.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"I am in touches began  methods");

UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self.view];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];

CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);

if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {
    //Set Animation Properties
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration: 1];

    if(gestureStartPoint.x > currentPosition.x){    //I am trying to move right

        ViewControllerTemplate *newView = [[ViewControllerTemplate alloc] initWithNibName:@"ViewControllerTemplate" bundle:nil];
        //Transition spin right
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
        //Push OnTo NavigationController
        [self.navigationController pushViewController:newView animated:YES];        
    }
    else {  //I am trying to move left
        if([viewDelegate getCurrentViewID] > 0){    //At view 0, should not pop anymore view
            //Transition Spin left
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    [UIView commitAnimations];
}
}

Más o menos, sólo dicen que cuando la derecha golpe de usuario, crear una nueva vista (ViewControllerTemplate) y pushViewController, y cuando el usuario deja de golpe, popViewController. Sin embargo, desde que cambio de opinión y no quiero poner en práctica la barra de pestañas. Así que cambie de código en applicationDidFinishLaunching en AppDelegate a estos a continuación y el pushViewController en touchesMoved en View1.m dejar de trabajar. Estoy seguro de que llegar a determinado lugar, pero cuando se pushViewController del NEWVIEW, nada sucede. Siento que cuando me llevó a cabo la UINavigationController, mi vista no se empuja en la pila correctamente más. ¿Alguna idea de por qué y cómo solucionarlo

view1 = [[View1 alloc] init];
[window addSubview:View1.view];
¿Fue útil?

Solución

Si alguien ejecuta en el mismo problema, aquí está la solución Reemplazar lo que tengo para applicationDidFinishLaunching () hasta allí para este

view1 = [[View1 alloc] initWithNibName:@"View1" bundle:nil];    //Create the first view
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1];
navigationController1.navigationBar.tintColor =[UIColor blackColor];
view1 = navigationController1;  
[window addSubview:view1.view];
[window makeKeyAndVisible];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top