调试时遇到警告问题

时间:2015-11-16 12:49:52

标签: ios objective-c ios9 uimodalpresentationstyle

背景

我正在截取viewController并在collectionViewCell中展示它。 collectionViewCell的布局是水平的,但是当我选择一个视图然后旋转设备然后回到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版本:7.1
  • iOS:9.1

注意 - 我使用iOS8在Xcode 6.4上运行相同的代码,并且它运行时没有出现故障/警告。此外,我能够在调试区域中找到变量的值。

更多信息: -

断点 - 我把它放在下面的方法

- (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的值,像往常一样有框架之类的细节。

实际结果 -

上述警告。

我尝试调试的内容 -

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

提前致谢。

1 个答案:

答案 0 :(得分:3)

替代解决方案

根据您关于想要处理UICollectionView旋转的更新评论。您是否尝试将以下方法添加到包含集合视图的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];
    }];
}

OR

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

OR

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

Sample CollectionView Project From Apple

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

警告

关于您所看到的警告。您所说的代码并不重要,可能是由于为UIModalPresentationStyle类型的属性指定了无效值(如果没有更重要的代码则更难以实现)。您显示的代码也有一个小问题,您在autoresizingMask中使用管道(|)。这些可以编码为[UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight]