4

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.

Tommie C.
  • 12,895
  • 5
  • 82
  • 100
nikhil84
  • 3,235
  • 4
  • 22
  • 43
  • Please make this a proper question before it gets closed. Check the help for [asking](http://stackoverflow.com/help/asking) if needed. – sidyll Nov 16 '15 at 12:59
  • Make sure you haven't defined a type named `UIModalPresentationStyle` anywhere in your code. – Avi Nov 16 '15 at 13:01
  • where exactly do u get these warnings? in the debugger or in the editor ? – Teja Nandamuri Nov 16 '15 at 13:45
  • @Mr.T in debug area while I use command "po variable_name" to find out the value of any particular variable. – nikhil84 Nov 19 '15 at 05:45
  • @Avi I have checked my code with UIModalPresentationStyle and found **self.viewController.modalPresentationStyle = UIModalPresentationFormSheet;** – nikhil84 Nov 19 '15 at 05:47
  • what command exactly are u using to print in debugger ? – Teja Nandamuri Nov 19 '15 at 13:43
  • you need to include more details. Where excactly u put the breakpoint, what command u used to print the values!! – Teja Nandamuri Nov 19 '15 at 13:51
  • @TommieC. - self.viewController is a different part. As Avi asked me to search for modalPresentationStyle in my project so I did so and provided that in my comment. As for what I'm trying to achieve is that 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. – nikhil84 Nov 20 '15 at 05:24

1 Answers1

3

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].

Community
  • 1
  • 1
Tommie C.
  • 12,895
  • 5
  • 82
  • 100
  • Hi I added [collectionView.collectionViewLayout invalidateLayout] in cellForItemAtIndexPath method before initiating the collectionViewCell. Then I am able to get the right layout of collectionView but when I try to fetch the cell frame it's showing portrait frame (when I have rotated to landscape) and vice-versa. – nikhil84 Dec 02 '15 at 12:41