我正在构建一个iOS7应用程序,我正在尝试利用新的useLayoutToLayoutNavigationTransitions
效果。我有 2 个UICollectionViewControllers
当我执行以下操作时,我得到了过渡效果
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondVC.useLayoutToLayoutNavigationTransitions = YES;
[self.navigationController pushViewController:secondVC animated:YES];
这工作正常,但我想做的是进行 api 调用,然后在完成块中我想像这样推送到导航堆栈
[webAPI getDetailsWithParams:params andCompletionBlock:^(id dict) {
//some work on the result
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondVC.useLayoutToLayoutNavigationTransitions = YES;
[self.navigationController pushViewController:secondVC animated:YES];
} andErrorBlock:^(NSError *error) {
}];
但是每次都会崩溃,并带有以下消息
-[UICollectionView _invalidateLayoutWithContext:]: message sent to deallocated instance 0x17a26400
谁能告诉我在这种情况下我做错了什么?从完成块推送时如何获得过渡效果?
编辑:通过将其更改为以下内容,我能够过渡到第二个视图控制器。
MyLayout *layout = [[MyLayout alloc] init];
SecondViewController *expandedVC = [[SecondViewController alloc] initWithCollectionViewLayout:layout];
我还删除了随文件一起提供的 nib 文件。 NIB文件只是由一个集合视图组成,它是文件所有者视图。虽然我现在可以过渡,但我仍然不明白为什么我不能在块中做以前的笔尖方法。因此,如果有人能为我阐明这一点,我将不胜感激。
为了使用 UICollectionViewController 的 useLayoutToLayoutNavigationTransitions 进行转换,必须知道 SecondViewController 的布局。但是,如果使用 initWithNibName:bundle: 初始值设定项,则布局尚未在内部准备好,因此无法进行所需的转换。正如您在编辑的问题中提到的,您必须使用 [UICollectionViewController initWithCollectionViewLayout:] 来初始化您的第二个 UICollectionViewController。由于您的 xib 文件与您的类名同名,因此 SecondViewController.xib 将由 UICollectionViewController 的超类 UIViewController 自动加载。
我认为您是从不是主线程的线程进行UIKit调用的