男人我必须说如果不是这个网站,我就没有头发了,我现在可能已经跳过了一座桥。好!我的问题:
我正在使用带有xcode 4.4的故事板。 我有一个3视图控制器(5个真的,但其他我认为是无关紧要的)。视图控制器A按下以查看控制器B.视图控制器B在其导航栏上具有分段控件,具有2个段和后退按钮。视图控制器B在选择了段1的情况下加载。当用户选择段0时,然后实例化视图控制器C.在第一次推进时一切顺利。你从A推到B,然后当你按回它弹出到A.我的问题是当popToViewController到包含视图控制器A的数组列表时,它弹出,但它没有动画!我知道你在想什么,“Animate:YES dummy!”然而,动画是的......是啊?这是我的代码:
继承人在视图控制器B中进行了什么
-(IBAction)Previous:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)segmentSwitch:(id)sender;
{
if ([sender selectedSegmentIndex] == 0)
{
MapViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Map"];
[self.navigationController pushViewController:controller animated:NO];
}
else if ([sender selectedSegmentIndex] == 1) {
ListViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"List"];
[self.navigationController pushViewController:controller animated:NO];
}
}
继承人视图控制器C
-(IBAction)Previous:(id)sender
{
NSInteger index = -1;
ReportAppDelegate *appDelegate =
(ReportAppDelegate *)[[UIApplication sharedApplication]delegate];
MainOrangeTestViewController *orangeViewController = [appDelegate orangeViewController];
orangeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Orange"];
NSArray* newVCarray = [[NSArray alloc] initWithObjects:orangeViewController, nil];
self.navigationController.viewControllers = newVCarray;
for(int i=0 ; i<[newVCarray count] ; i++)
{
if([[newVCarray objectAtIndex:i] isKindOfClass:NSClassFromString(@"MainOrangeTestViewController")])
{
index = i;
}
}
[self.navigationController popToViewController:[newVCarray objectAtIndex:index] animated:YES];
}
- (IBAction)segmentSwitch2:(id)sender; {
if ([sender selectedSegmentIndex] == 0)
{
MapViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Map"];
[self.navigationController pushViewController:controller animated:NO];
}
else if ([sender selectedSegmentIndex] == 1)
{
ListViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"List"];
[self.navigationController pushViewController:controller animated:NO];
}
}
我知道当你实例化时,你正在创建一个新的视图控制器实例,以及创建一个新的导航堆栈(或类似的东西)。我想这可能与它有关。无论如何,为什么它不是流行音乐的动画?我希望在我当前的构建中实现一些东西,但是如果它需要重建那么就这样吧!任何帮助是极大的赞赏。我肯定在这个上完成了我的作业,但没有解决方案。
提前感谢所有人!
编辑:我应该添加从视图控制器B返回到A的初始POP是动画的。当您开始切换分段控件时,当您切换到查看控制器C时,回到视图控制器A不会为弹出窗口设置动画。因此,当您从A加载到B时,它会以成功的动画弹出。但是在切换之后它会弹回A而没有动画,动画方法是YES。
答案 0 :(得分:0)
您是否只是试图按A-> B-> C然后再次弹回A,跳过B?如果是这样,则无需修改导航控制器的viewControllers属性。
// in vcC.m ...
-(IBAction)Previous:(id)sender
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
查看class reference中不同种类的流行音乐。您可以弹回一个,或弹出到根,或弹出到历史记录中的特定VC。这样做的方法是读取 viewControllers堆栈(不写它),找到要弹出的VC,然后使用代码中的popTo ...方法。
但听起来像popToRoot是你需要的。
答案 1 :(得分:0)
对你的情况仍然有点困惑,但这是另一个提示:你可以事先创造历史。假设您要从VC0推送到VC2,并且在弹出时,您希望从VC2弹出到VC1或VC0。完全可行:
// in VC0.m, animated push to VC2
// push to vc1 invisibly
[self.navigationController pushViewController:vc1 animated:NO];
// we've made history! now push visibly to vc2
[self.navigationController pushViewController:vc2 animated:YES];
选择弹回的位置......
// in VC2.m
if (/* user needs a regular pop back to VC1 */) {
[self.navigationController popViewControllerAnimated:YES];
} else // pop back two, to VC0
NSArray *viewControllers = [self.navigationController viewControllers];
// we're not assuming that vc0 is the root here, the top of the navigation stack
// is at index=count-1. self is at the top. a regular pop is just below == count-2.
// two pops is at count-3, and so on.
NSInteger backBackIndex = viewControllers.count - 3;
// in case we get here by some other pushing path, worst case pop is to the root
backBackIndex = MAX(backBackIndex, 0);
UIViewController *backBackVC = [viewControllers objectAtIndex:backBackIndex];
[self.navigationController popToViewController:backBackVC animated:YES];
}