我有一个嵌入在UINavigationController中的UITableViewController,我试图实现Peek& amp;弹出TableView。我有"偷看"部分工作完美,但当我尝试" pop"进入下一个ViewController,我是一个单元格"偷看"并显示下一个单元格。我是"弹出"进入UICollectionView,正如我所提到的," peek"一半表示正确的单元格,但是" pop"才不是。只有在我使用[self.navigationController showViewController:viewControllerToCommit sender:nil];
或[self.navigationController pushViewController:viewControllerToCommit animated:YES];
执行" pop"时才会出现此问题。
我尝试使用[self presentViewController:viewControllerToCommit animated:YES completion:nil];
并显示正确的单元格,但这并没有给出我需要的导航元素,所以我无法使用它(除非有办法让所有的导航元素回来了。)
我最初的想法是,我的应用程序如何计算CollectionViewCell的大小有问题。这是我正在使用的代码,虽然看起来它可以正常使用Peek&流行。
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize collectionViewBounds = collectionView.bounds.size;
int navigationHeight = self.navigationController.navigationBar.bounds.size.height;
int toolbarHeight = self.navigationController.toolbar.bounds.size.height;
int statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
int cellHeight = collectionViewBounds.height - (navigationHeight + statusBarHeight + toolbarHeight);
int cellWidth = collectionViewBounds.width;
return CGSizeMake(cellWidth, cellHeight);
}
为了增加我的困惑," pop"当TableView中的第一个或最后一个项目被“偷看”时,它可以完美地工作。对此的任何帮助将不胜感激。
答案 0 :(得分:2)
So I finally figured out what was causing this problem. My app is a Universal app, and I use a Popover Segue on iPads. In viewWillAppear
of my ViewController that is "popping" incorrectly, I use [self setPreferredContentSize:CGSizeMake(400.0, 600.0)]
to determine the size of the Popover on an iPad. Once I removed that line, my Peek & Pop worked perfectly.
I ended up adding a new property to my ViewController @property BOOL fromPeek
and set that property to YES
in - (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
of my previewing ViewController. Finally, I modified my viewWillAppear
to be if(!fromPeek) [self setPreferredContentSize:CGSizeMake(400.0, 600.0)];
and the problem is now solved!