与pushViewController有问题!救命
-
21-09-2019 - |
题
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];
上面的代码是从我的appDelegate类(的applicationDidFinishLaunching)。视图1和视图2是UIViewController中。这是我最初的设计我的应用程序,该应用程序有两个选项卡,(厂景和视图2)。下面的代码,实现视图1发生什么,当向左或向右轻扫用户。
- (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];
}
}
差不多,它只是说,当用户刷卡的权利,它创建一个新的视图(ViewControllerTemplate)和pushViewController,当离开用户刷卡,popViewController。然而,因为我改变了主意,不想执行标签栏。所以,我改变我在的applicationDidFinishLaunching代码的appDelegate这些下面和View1.m停止工作pushViewController在touchesMoved。我相信,它到那里,但是当它的NewView的的pushViewController,没有发生。我觉得当我拿出的UINavigationController,我的观点不被压入栈正常了。任何想法,为什么,以及如何解决它。
view1 = [[View1 alloc] init];
[window addSubview:View1.view];
解决方案
如果有谁碰到了同样的问题,这里是解决方案 更换什么,我有在applicationDidFinishLaunching()那里本
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];
不隶属于 StackOverflow