0
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]; 

Le code ci-dessus provient de ma classe appDelegate (applicationDidFinishLaunching). View1 et View2 sont UIViewController. C'est ainsi que j'ai conçu mes applications, que les applications ont deux onglets (view1 et view2). Le code ci-dessous, implémenter ce qui se passe dans View1, lorsque l'utilisateur balaye à gauche ou à droite.Avoir un problème avec pushViewController !! Aide

- (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]; 
} 
} 

Quasiment, il de dire que lorsque le droit swipe utilisateur, il crée une nouvelle vue (ViewControllerTemplate) et pushViewController, et lorsque le swipe utilisateur gauche, popViewController. Cependant, puisque je change d'avis et ne veux pas mettre en œuvre la barre d'onglets. Donc, je change mon code dans applicationDidFinishLaunching dans appDelegate à ceux ci-dessous et le pushViewController dans touchesMoved dans View1.m arrêter de travailler. Je suis sûr que cela arrivera là, mais quand il pushViewController de la nouvelle vue, rien ne se passe. Je me sens comme quand j'ai sorti le UINavigationController, mes vues ne sont plus poussées sur la pile correctement. Toute idée pourquoi et comment le résoudre

view1 = [[View1 alloc] init]; 
[window addSubview:View1.view]; 

Répondre

1

Si quelqu'un a déjà couru dans le même problème, voici la solution Remplacer ce que j'ai pour applicationDidFinishLaunching() là à ce

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]; 
+0

-vous savoir par hasard comment vous pouvez pousser les données à une autre vue sur UITouch comme vous le faisiez avant. Comme comment nous le faisons sur didselectforrowatindexpath. – lifemoveson