I'm working with an existing code. Here a popovercontroller has been declared in .h file and its giving me error in implementation line.
.h file
@property (nonatomic, strong) VFImagePickerController *imagePicker;
@property (nonatomic, strong) UIPopoverController *popoverController;
@property (nonatomic, strong) UINavigationController *targetVC;
.m file:
Please suggest how to fix this.
Uncomment the synthesize line and remove underscore to look like this:
@synthetize popoverController;
And replace every _popoverController var name in your .m file to popoverController
It appears that your class is a subclass of
UIViewController
.UIViewController
has a private, undocumented ivar of_popoverController
. Since you are trying to create an ivar in your class with the same name, you are getting an error.The easiest thing to do is to rename your
popoverController
property to something different. Otherwise your app might get flagged for using a private API.This problem occurs because your superclass, UIViewController, already has an instance variable named
_popoverController
. As a result, neither the default synthesis nor your explicit (commented)@synthesize
directive have access to the instance variable that they want to use to provide thepopoverController
property.You can resolve this by either renaming your property, or explicitly synthesizing the property to use a different instance variable name:
(Also note that the "local" prefix isn't necessarily best practice for your property names or instance variables; take a second to consider your preferred naming convention and pick a property/instance variable name appropriately.)
Do not name your instance variable (or property) popoverController. As mentioned above UIViewController has an instance variable declared as _popoverController. (Who knows why.)
It would be wise not to give your popover controller a generic name anyway, because, for example, if you decide to add more than one popover to a toolbar, you'll have to create more than one popover controller to accomplish this.
If you look at Apple's sample code, you can see how they do this:
http://developer.apple.com/library/ios/#samplecode/Popovers/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010436
Check out the private properties section in DetailViewController. There, you will see three controller objects and none with the generic name "popoverController”. That will cause problems.