وجود مشكلة مع 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). View1 و View2 هما UiviewController. هذه هي الطريقة التي أقوم بها في الأصل بتصميم تطبيقاتي ، وأن التطبيقات لديها علامات تبويب ، (View1 و View2). الكود أدناه ، قم بتنفيذ ما يحدث في العرض 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 إلى هذه أدناه و PushViewController في العمل touchesmoved في العرض 1.M توقف. أنا متأكد من أن الأمر يصل إلى هناك ، ولكن عندما يكون PushViewController من NewView ، لا شيء يحدث. أشعر وكأنني عندما أخرجت uinavigationController ، فإن وجهة نظري لم تعد مدفوعة على المكدس بشكل صحيح بعد الآن. أي فكرة لماذا وكيفية إصلاحه
view1 = [[View1 alloc] init];
[window addSubview:View1.view];
المحلول
إذا واجه أي شخص نفس المشكلة ، فإليك الحل استبدل ما لدي للتطبيق DiDidFinishLaunching () هناك إلى هذا
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];