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:


The trouble is that self.preferredContentSize is only available in iOS 7, hence the exception. In previous versions of this template this line didn’t seem to matter – and by simply commenting it out the problem goes away, seemingly without any functionality issues.

Apple like doing this at times – which goes to show that they rather you never look back at older iOS versions.

If you don’t feel like commenting the line out completely you can test if device OS supports it by amending the whole function like this:


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

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