私はobjective-Cとココアが初めてです。
私の UIViewController では、さまざまなメソッドで AppDelegate に複数回アクセスする必要があります
A. すべてのメソッドを呼び出している:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
より多くのパフォーマンスを消費しますか?
B. UIViewController でグローバル パラメータを作成しようとしました。
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface Login_ViewController : UIViewController<UITextFieldDelegate,UIImagePickerControllerDelegate>{
AppDelegate *appDelegate;
}
実装と使用法:
- (void)viewDidLoad
{
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.businessId = [businessId integerValue];
}
- (BOOL)credentialsValidated
{
appDelegate.businessId = [[NSUserDefaults standardUserDefaults] integerForKey:BUSINESS_ID];
}
しかし、警告が表示されます(コードは機能しますが)
Incompatible integer to pointer conversion assigning to 'NSInteger *' (aka 'int *') from 'NSInteger' (aka 'int');
appDelegate での businessId の宣言は次のとおりです。
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property NSInteger *businessId;
そして実装:
@implementation AppDelegate
@synthesize businessId;