Noob properties error

2019-05-06 20:14发布

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:
The error

Please suggest how to fix this.

4条回答
Bombasti
2楼-- · 2019-05-06 20:36

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-05-06 20:38

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.

查看更多
Rolldiameter
4楼-- · 2019-05-06 20:44

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 the popoverController property.

You can resolve this by either renaming your property, or explicitly synthesizing the property to use a different instance variable name:

// Either
@property (nonatomic, strong) UIPopoverController *localPopoverController
// Or
@synthesize popoverController = _localPopoverController;

(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.)

查看更多
淡お忘
5楼-- · 2019-05-06 20:48

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.

查看更多
登录 后发表回答