세 개의 탭 표시 줄 컨트롤러가 있습니다. 이러한 탭 표시 줄 컨트롤러에는 다른보기로 이동하는 단추가 있습니다. 이러한 뷰 중 일부는 탭 표시 줄 컨트롤러와 동일한 다른 뷰 컨트롤러에 있지만 일부는 그렇지 않습니다. 이러한 다양한보기는 차례로 다른보기로 이동할 수 있습니다. 실제로 사용자는이 방법으로 새로운 관점을 영원히 계속할 수 있습니다. 세 가지 주요보기는 NewsFeedVC ProfileVC 및 NotificationsVC입니다. 그런 다음 보조 뷰에는 VotesListVC가 포함됩니다. 의도 된 사용법은 사용자가 세 개의 탭 중 하나를 선택하여 스택에서 더 많은 뷰 컨트롤러를 영원히 터뜨릴 수 있다는 것입니다. 사용자는 내비게이션 뒤로 버튼을 클릭하여 원래보기로 이동하거나 다른 탭을 누를 수 있습니다. 다른 탭을 누르면 이전 스택의 뷰 컨트롤러 스택이 해제됩니다. 원래 탭으로 돌아 가면 루트보기 컨트롤러가 나타납니다. 문제는 내 코드가보기 컨트롤러가 마지막인지 판별하는 것을 터무니없이 엉망으로 만들었다는 것입니다. 이 응용 프로그램에서는 Storyboard를 선택하지 않았으므로 모든 탐색을 직접 수행해야합니다. 내 질문은 스택에 무엇이 있는지와이를 제거하는 방법을 알 수있는 올바른 방법은 무엇입니까? 다음은 일부 코드입니다.네비게이션 스택에 여러 호출 추가
//for when the user wants to leave an individual post allViewControllers is an array
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
-(void)backTapped{
if (_postKey) {
ActivityViewController *newVC = [allViewControllers objectAtIndex:1];
[allViewControllers insertObject:newVC atIndex:0];
[allViewControllers removeLastObject];
self.navigationController.viewControllers = allViewControllers;
CATransition* transition = [CATransition animation];
transition.duration = 0.2f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
}
}
//Here is how I handle leaving the profileVC, I have booleans determining what view it is from.
-(void)backTapped{
if (fromWorldFeed) {
WorldFeedViewController *newVC = [allViewControllers objectAtIndex:1];
newVC.retainTablePosition=true;
[allViewControllers insertObject:newVC atIndex:0];
[allViewControllers removeLastObject];
self.navigationController.viewControllers = allViewControllers;
[self.navigationController popViewControllerAnimated:NO];
}else if(_fromActivity){
ActivityViewController *newVC = [allViewControllers objectAtIndex:1];
[allViewControllers insertObject:newVC atIndex:0];
[allViewControllers removeLastObject];
self.navigationController.viewControllers = allViewControllers;
}else{
VotesListViewController *newVC =[allViewControllers objectAtIndex:1];
[allViewControllers insertObject:newVC atIndex:0];
[allViewControllers removeLastObject];
self.navigationController.viewControllers =allViewControllers;
}
CATransition* transition = [CATransition animation];
transition.duration = 0.2f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
}
변경된 사항을 알기 위해로드 할 때 탭 표시 줄 인덱스를 저장하고 어떻게 든 이전 탭보기 스택을 해제 할 수 있습니다. 사용자는 대부분 하나 개 또는 두 개의보기로 이동할 수 있다면
-(void)setTabBarIndex{
NSInteger tabBarIndex =self.tabBarController.selectedIndex;
NSString *tabBarStr=[@(tabBarIndex) stringValue];
[[NSUserDefaults standardUserDefaults]setObject:tabBarStr forKey:@"tabBarIndex"];
}
이 코드는 잘 될 것입니다. 그러나 사용자가 앱을 자세히 살펴볼 때 고려해야 할 문제가 있습니다. 내 응용 프로그램 대리인이이를 관리 할 수있는 방법이 있습니까?
탭당 탐색 컨트롤러가 없는데 왜 탭을 전환 할 때 이전 활성 탭의 탐색 컨트롤러에 루트로 팝업하도록 지시해야합니다. – Paulw11