调试时遇到警告问题

Facing warning issue while debugging

背景

我正在截取 viewController 的屏幕截图并将其显示在 collectionViewCell 中。 collectionViewCell 的布局是水平的,但是当我 select 一个视图然后旋转设备然后再回到 collectionView 时,布局是垂直的。

调试:我在我的代码中放置了一个断点,在调试区域我试图检查一个变量的输出,这是下面的警告开始出现的地方。

**Warning:**

error: property 'modalPresentationStyle' declared with incompatible types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: instance method 'modalPresentationStyle' has incompatible result types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: property 'modalPresentationStyle' declared with incompatible types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: instance method 'modalPresentationStyle' has incompatible result types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: property 'modalPresentationStyle' declared with incompatible types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
error: instance method 'modalPresentationStyle' has incompatible result types in different translation units ('UIModalPresentationStyle' vs. 'UIModalPresentationStyle')
note: declared here with type 'UIModalPresentationStyle'
note: instance method 'modalPresentationStyle' also declared here
note: declared here with type 'UIModalPresentationStyle'
note: declared here with type 'UIModalPresentationStyle'
note: instance method 'modalPresentationStyle' also declared here
note: declared here with type 'UIModalPresentationStyle'
note: declared here with type 'UIModalPresentationStyle'
note: instance method 'modalPresentationStyle' also declared here
note: declared here with type 'UIModalPresentationStyle'
error: 6 errors parsing expression

我正在使用:-

注意- 我在 Xcode 6.4 运行 上使用 iOS8 的相同代码 运行 没有 glitch/warnings。此外,我能够在调试区域中找到变量的值。

更多信息:-

断点-我放在下面的方法里

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    UIViewController *viewController = (UIViewController *)_tabControllers[(NSUInteger)indexPath.row];

    /* Trying to debug above viewController in debug area */
    /* Some code is here also but of no use */

    cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    return cell;

}

在调试区域中触发的命令 -

po viewController

预期结果-

viewController 的值,细节如往常一样。

实际结果 -

上述警告。

我正在尝试调试的内容 -

collectionView 单元格的布局在 iOS 9 中自动更改(旋转后一个在另一个下面),而 iOS 8 中的其他布局(水平视图)是完美的。

提前致谢。

替代解决方案

基于您关于想要处理 UICollectionView 的旋转的最新评论。您是否尝试过将以下方法添加到包含 Collection View 的 UIViewController 中?

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        [self.collectionView performBatchUpdates:^{
            [self.collectionView setCollectionViewLayout:self.collectionView.collectionViewLayout animated:YES];
        } completion:nil];
    }];
}

在您的旋转视图方法中,您可以在 UICollectionView 上调用 invalidateLayout。

您可以尝试将 UIImageView 放入集合视图单元格并使用自动布局。然后将视图控制器的快照设置为UIImageView上的图像。

Sample CollectionView Project From Apple

80+ Other Questions on SO(可能提供一些见解)

警告

关于您看到的警告。您所说的代码不重要可能是由于为 UIModalPresentationStyle 类型的 属性 分配了无效值引起的(没有更重要的代码就很难更精确)。此外,您显示的代码还有一个小问题,即您在 autoresizingMask 中使用管道 (|)。这些可以编码为 [UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight]