Search code examples
iosipadios7universal-storyboard

Xcode 6 Universal storyboard NSKeyedUnarchiver initForReadingWithData error


I've migrated my project from iOS 7 to iOS 8 keeping iOS 7 support. Since i've redone all the graphics i've thrown away the old storyboard and created a new one using the new universal storyboard and size classes.

Everything works fine for iOS 8 iPhone/iPad and iOS 7 iPhone but on iOS 7 iPad i'll keep getting the following error:

[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?

the app didn't even reach application:didFinishLaunchingWithOptions and i know the problem is the storyboard, because if i create an empty one the app start fine.

What am i missing? Do i need an ad hoc storyboard only for ipad to support iOS 7? or there is another way?

EDIT:

during some test, i've found that the method that throw the exception is:

[storybord instantiateInitialViewController];

or

[storyboard instantiateViewControllerWithIdentifier:@"id"];

i've launched the application with an empty storyboard and loaded my storyboard in the app delegate. The storyboard is not nil, but the app crash on that method. Loading a view controller that is not the initial one doesn't change the result.


Solution

  • I was having this same issue and narrowed it down to a Collection View that I had installed for my compact/any size class, but uninstalled for my any/any size class. It seems that iOS 7 has trouble with prototype cells when the collection view they belong to is uninstalled in the active size class. Running on iOS 8 works fine so if you're only supporting iOS 8 and above, you won't run into this issue.

    Prototype cell(s) active (Doesn't work): Uninstalled Collection View with Prototype Cell

    Prototype cell(s) removed (Works): Uninstalled Collection View without Prototype Cell

    To solve this, I'm going to create a xib that will be programmatically loaded for iPad and keep the storyboard for use on iPhone. Since the view in question doesn't need a Collection View on iPad, the xib should be pretty simple, but it still sucks to have to do this from a maintenance standpoint.