That's crashing because after going back, FirstViewController is using 
SecondViewController as it's collectionView's delegate & dataSource, resulting 
in messages to a dealloc-ed object. Turn on NSZombies to see this.

This appears to happen because when going Back from your 
SecondViewController's, FirstViewController is using SecondViewController as 
its collection view's delegate / dataSource. Note that if you make a strong 
reference to SecondViewController someone, so it isn't dealloced, 
FirstViewController will start drawing its content using SecondViewController's 
colors via SecondViewController's cellForItemAtIndexPath.

One way to fix that is to add, in both view controllers:

- (void)viewWillAppear:(BOOL)animated  {
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
}

Also good practice to do:

- (void)dealloc
{
    self.collectionView.delegate = nil;
    self.collectionView.dataSource = nil;
}

That lets it run OK, but I'm not sure *why* your FirstViewController ends up 
using Second as its delegate. The project doesn't contain any code that 
directly does that. So I can't tell if the -viewWillAppear above is a Band-Aid, 
or a correct solution. Perhaps it is with 
useLayoutToLayoutNavigationTransitions? I haven't used that before.

Anyway that should get you started.

On May 20, 2015, at 7:45 AM, cocoa-dev-requ...@lists.apple.com wrote:

> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Tue, 19 May 2015 23:46:28 -0500
> From: Luther Baker <lutherba...@gmail.com>
> To: Cocoa Developers <Cocoa-dev@lists.apple.com>
> Subject: Collection Views Breaking
> Message-ID:
>       <cal5mv1m-u82zgvr6uacgy+9avn-cc1uo6++xvcfot7sd8qu...@mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> I've got a simple iOS project consisting of 2 collection view controllers
> and a navigation controller.
> 
> Tapping any item in the first collection view simply pushes the second
> collection view on the stack.
> 
> Problem is, when I tap "< Back" and then manually scroll up ... the app
> crashes with a EXC_BAD_ACCESS error in main.
> 
> Nothing is logged ... and the stack in the thread looks something like
> 
> 0 objc_msgSend
> 16 UIApplicationMain
> 17 main
> 18 start
> 19 start
> 
> with 17 main highlighted.
> 
> /////
> 
> In the code, FirstViewController and SecondViewController are almost
> identical save for one line. I am specifically looking at what line 24 in
> SecondViewController does to the push transition.
> 
>        self.useLayoutToLayoutNavigationTransitions = YES;
> 
> Upon running, the collection view "push" animation looks fine - and the "<
> Back" button actually works ... but once I get back to FirstViewController,
> the original colors never come back. In addition, when I scroll up, I get
> the error listed above.
> 
> I've thrown together a small project to demonstrate:
> https://github.com/LutherBaker/CollectionViewDemo
> 
> Thoughts? It feels like I'm not referencing something I should be ...
> 
> Thanks,
> -Luther
> 
> PS: I think you may ignore this but note that when you initially select an
> item in the FirstViewController and "push" - the console spits lots and
> lots of
> 
> *Snapshotting a view that has not been rendered results in an empty
> snapshot. Ensure your view has been rendered at least once before
> snapshotting or snapshot after screen updates.*
> which I assume is simply a bug or non-relevant logging accidentally left in
> the framework.
> 


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to