0
自學iOS編程,從this book開始。 我碰到錯誤的「屬性'MainViewController'在'AppDelegate *'類型的對象上找不到'錯誤:對象'AppDelegate *'丟失屬性
我有雙重和三重檢查,我正確地跟着代碼,甚至從頭開始重新編寫。嘗試了一些解決方案,但沒有工作,很少正確地匹配我的問題。任何幫助嗎?
AppDelegate.m(其中錯誤所在)
#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
雖然這假定MainViewController是rootViewController,但我認爲這是一個安全的假設。 – Abizern
也意味着要增加這個假設,現在我相應地改進了答案。 – Karl