How to fix "setPreferredContentSize" error in iOS 6 iPad Apps

xcodeThere is a bug in Xcode 5 in the Master Detail Template which manifests when you try and run it on iPads running iOS 6.x. The app will work fine on iOS 7 but won’t even start in iOS 6. The full error message is something like this:

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[MasterViewController setPreferredContentSize:]: unrecognized selector sent to instance 0x7a95580’

The problem is with a code snippet in MasterViewController.m, first method. It looks like this:

This content is for members only.

Here we check if our current view controller (self) responds to preferredContentSize, and if it does, we’ll call what Apple recommend. If that’s not the case we simply won’t.

Adios exception!

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

2 thoughts on “How to fix "setPreferredContentSize" error in iOS 6 iPad Apps

  1. The problem is, setPreferredContentSize is only available in IOS 7.0.

    When you found the setPreferredContentSize you should do something like this :

    at the header

    now wherever u need to check whether ios version is greater or less and similarly set the contentsize

Leave a Reply to Ankit Gupta Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.