在尝试将 managedObjectContext 分发到视图控制器时,我收到该错误:在“UIViewController *”类型的对象上找不到属性“managedObjectContext” AppDelegate.m 中的此代码是错误的根源:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *searchController = [[SearchCriteriaViewController alloc] initWithNibName:@"SearchCriteriaViewController" bundle:nil];
UIViewController *managementController = [[WineManagementViewController alloc] initWithNibName:@"WineManagementViewController" bundle:nil];
managementController.managedObjectContext = self.managedObjectContext;
WineManagementViewController 中的代码如下所示:
@interface WineManagementViewController : UIViewController <NSFetchedResultsControllerDelegate>
{
IBOutlet UIButton *countryButton;
WineStore *store;
}
- (IBAction)newCountry:(id)sender;
@property (strong, nonatomic) UIPopoverController *poCtrl;
@property (strong, nonatomic) WineStore *store;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
这是实施的开始:
@implementation WineManagementViewController
@synthesize store, managedObjectContext;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
...
如果我想以这种方式访问该属性,或者如果我想使用 setter 方法访问它,则找不到该属性。有谁知道为什么找不到这个属性?