これは私の最後のものへのフォローアップの質問です:iOS: Initialise object at start of application for all controllers to use。iOSのグローバルインスタンスへのアクセスがありません(工場でビルド)
私は(DBプレフィックスを無視する)は次のように自分のアプリケーションを設定している:私は、アプリケーションを介して段階的に移動し、最後
AppDelegateに問題を投稿します
DBFactoryClass // Built a DataManaging Object for later use in the app
DBDataModel // Is created by the factory, holds all data & access methods
DBViewControllerA // Will show some of the data that DBDataModel holds
moreViewControllers that will need access to the same DBDataModel Object
。 H
#import "DBFactoryClass.h"
AppDelegate.m
- (BOOL)...didFinishLaunching...
{
DBFactoryClass *FACTORY = [[DBFactoryClass alloc ]init ];
return YES;
}
DBFactoryClass.h
#import <Foundation/Foundation.h>
#import "DBDataModel.h"
@interface DBFactoryClass : NSObject
@property (strong) DBDataModel *DATAMODEL;
@end
DBFactoryClass.m
#import "DBFactoryClass.h"
@implementation DBFactoryClass
@synthesize DATAMODEL;
-(id)init{
self = [super init];
[self setDATAMODEL:[[DBDataModel alloc]init ]];
return self;
}
@end
ViewControllerA.h
#import <UIKit/UIKit.h>
#import "DBDataModel.h"
@class DBDataModel;
@interface todayViewController : UIViewController
@property (strong)DBDataModel *DATAMODEL;
@property (weak, nonatomic) IBOutlet UILabel *testLabel;
@end
ViewControllerA.m
#import "todayViewController.h"
@implementation todayViewController
@synthesize testLabel;
@synthesize DATAMODEL;
- (void)viewDidLoad
{
todaySpentLabel.text = [[DATAMODEL test]stringValue]; // read testdata
}
@end
DBDataModel.h
#import <Foundation/Foundation.h>
@interface DBDataModel : NSObject
@property (nonatomic, retain) NSNumber* test;
@end
DBDataModel.m
#import "DBDataModel.h"
@implementation DBDataModel
@synthesize test;
-(id)init{
test = [[NSNumber alloc]initWithInt:4]; // only a testvalue
return self;
}
@end
アプリは罰金のビルド、および起動するが、ラベルは空白のままです。だからオブジェクトが存在しない(しかし、私はこれがエラーメッセージになるだろうと思う)、または何かが私のセットアップに間違っている。何かご意見は?
こんにちは - アドバイスをいただきありがとうございます - 私は最初から始めます、ストーリーボードは実際に何が起こっているか見るためにあまりにも多く隠れるようです:) –
私は非常に古い電話とmiscliked 、一度私のラップトップに再び私は、何とか私は携帯電話から投票を切り替えることはできません。 –
私はそれを管理しました) 私は独自のtabbarcontrollerを書いて、工場にすべてのビューを作成させ、共通のデータモデルをすべてに直接追加してからtabbarcontrollerに送信しました。 非常に小さな質問:なぜあなたはサンプルプロジェクトのいくつかのファイルに@classを入れましたか?それを残して、うまくいきますか? –