views:

720

answers:

3

In a universal binary iPhone/iPad app of mine, users are able to adjust preferences in a view controller that's presented modally. On the iPhone, the settings panel is presented with presentModalViewController:animated:, and on the iPad, I use a UIPopoverController.

I'm having a heck of a time completely isolating the UIPopoverController code away from the iPhone code. Everytime I compile for the iPhone, I get the following error:

dyld: Symbol not found: _OBJC_CLASS_$_UIPopoverController
  Referenced from: /var/mobile/Applications/CBB37F87-AA6D-47E2-823A-E259E3268A32/MyApp debug.app/MyApp
  Expected in: /System/Library/Frameworks/UIKit.framework/UIKit

This is of course because UIKit on the iPhone doesn't have a UIPopoverController class. Does anybody have advice for how to effectively isolate the iPad API includes from the iPhone code, so I can actually run my code?

+2  A: 

Ahhhh nevermind. Check out Apple's example app "TopPaid"

It's kinda hacky, but it works. Wish there was a more elegant solution...

Class cls = NSClassFromString(@"UIPopoverController");
if (cls != nil)
{
    UIPopoverController *aPopoverController =
        [[cls alloc] initWithContentViewController:self.masterViewController];
    self.popoverController = aPopoverController;

    [aPopoverController release];

    [popoverController presentPopoverFromBarButtonItem:barButtonItem
                              permittedArrowDirections:UIPopoverArrowDirectionUp
                                              animated:YES];
}
alexbw
I was having the same above problem. When I run the my universal application on iPhone it crashes even though I check for "UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad" before instantiating the Popover. I solved it with this. Thanks for the answer.
ravinsp
+1  A: 

You could also weak link to UIKit.

KennyTM
A: 

I had the same problem, this is my post and solved my issue. http://stackoverflow.com/questions/3001374/symbol-not-found-objc-class-uipopovercontroller

Regards,
Paul

Paul Peelen