2

私は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;
4

3 に答える 3

4

アプリ デリゲートの宣言から を削除*します。

@property NSInteger (assign) businessId;

NSIntegerはプリミティブであるため、オブジェクト ポインターは必要ありません。

于 2012-12-11T11:12:38.627 に答える
1

A. 1 秒あたり 100000000 と呼ばなければ、パフォーマンスが低下することはありません。ところで、決してsmthを仮定することはありません - 常に測定してください。Time Profiler というツールがあり、これを使用してすべてのボトルネックを見つけます。

B. NSInteger は単なる int の typedef です。POD 型であり、ObjC オブジェクトではないため、メッセージを送信できません。NSInteger* の代わりに NSInteger を使用します。

于 2012-12-11T11:12:48.927 に答える
1

この #define DELEGATE (AppDelegate *)[[UIApplication sharedApplication] delegate]; のように AppDelegate を定義できます。必要な場所で DELEGATE を使用できるようになりました。

于 2012-12-16T05:35:52.190 に答える