Search code examples
iosobjective-cios9uimodalpresentationstyle

Facing warning issue while debugging


Background

I'm taking screenshot of a viewController and presenting that in collectionViewCell. Layout of collectionViewCell is horizontal but as I select a view then rotate the device then later going back to collectionView the layout comes as vertical.

To debug: I put a break point in my code and in debug area I tried to check output of a variable, which is where the warning below started appearing.

**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

I'm using :-

  • Xcode version: 7.1
  • iOS: 9.1

Note- Same code I ran on Xcode 6.4 with iOS8 and it's running without a glitch/warnings. Also, I was able to find values for variables in debug area.

More Info :-

Break point - I put it in below method

- (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;

}

Command fired in debug area -

po viewController

Expected result -

Value of viewController with detail like frame as usual.

Actual Result -

Above mentioned warning.

What I'm trying to debug -

Layout of collectionView cell is changing automatically (one below another coming after rotation) in iOS 9 where else in iOS 8 layout (horizontal view) was prefect.

Thanks in advance.


Solution

  • Alternative Solutions

    Based on your updated comment about wanting to handle rotation of a UICollectionView. Have you tried adding the following method to your UIViewController containing the Collection View?

    - (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

    In your rotation view methods you could call invalidateLayout on the UICollectionView.

    OR

    You could try putting an UIImageView into the collection View cell and use auto layout. Then set the snapshot of the view controller as the image on the UIImageView.

    Sample CollectionView Project From Apple

    80+ Other Questions on SO (may provide some insight)

    Warnings

    Regarding the warnings that you are seeing. The code that you are saying is not important is likely caused by assigning an invalid value to a property of type UIModalPresentationStyle (More precision is difficult without more significant code). Also the code that you do show has a small issue where you are using pipes (|) in your autoresizingMask. These can be coded as [UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight].