Reputation: 1
Teaching myself iOS Programming, and starting by following this book. I ran into error "Property 'MainViewController' not found on object of type 'AppDelegate *'.
I've double and triple checked that I followed the code correctly, even restarted from scratch. I've scoured StackOverflow and tried a few solutions but none worked and few properly match my issue. Any help?
AppDelegate.m (where the error lies)
#import "AppDelegate.h"
#import "WeatherForecast.h"
#import "MainViewController.h"
@implementation AppDelegate
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
WeatherForecast *forecast = [[WeatherForecast alloc] init];
self.MainViewController.forecast = forecast;
// Override point for customization after application launch.
MainViewController *controller = (MainViewController *)self.window.rootViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
MainViewController.h
#import "FlipsideViewController.h"
#import "WeatherForecast.h"
#import <CoreData/CoreData.h>
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
- (IBAction)showInfo;
- (IBAction)refreshView:(id) sender;
- (void)updateView;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) WeatherForecast *forecast;
@end
Upvotes: 0
Views: 482
Reputation: 1233
The problem should be in your second line of application:didFinishLaunchingWithOptions
. self.MainViewController
is expecting a property in your AppDelegate. Just remove this line and add controller.forecast = forecast;
before return YES.
At this point you got a reference to your MainViewController and can set the property safely (assuming that MainViewController is set up as the current rootViewController through your Storyboard or XIB).
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
WeatherForecast *forecast = [[WeatherForecast alloc] init];
// Override point for customization after application launch.
MainViewController *controller = (MainViewController *)self.window.rootViewController;
controller.managedObjectContext = self.managedObjectContext;
controller.forecast = forecast;
return YES;
}
Upvotes: 1