Plsのはこれで私を助け:アクセスAppDelegateのインスタンスが、エラー:EXC_BAD_ACCESS
AppDelegateは、「利用者」と呼ばれる引数があります。
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
User *user;
}
@property (nonatomic, retain) User *user;
を、私は延期のViewControllerにユーザーインスタンスを初期化:
User *userInfo = [[User alloc] initWithRealName:realName UserId:userId];
とAppDelegateのにユーザーを設定します。
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.user = userInfo;
を第二のViewControllerで
、私は使用者の本名を得ることができ、そこには問題はありません。そこ
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *realName = appDelegate.user.realName;
しかし、私は別のViewControllerにプッシュして、私はちょうど今のように、ユーザーの本名を取得したい、 けどエラーです:EXC_BAD_ACCESS:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
User *user = appDelegate.user;
NSLog(@"I am in noticeDetailViewController:%@",user.realName);***//ERROR***
私は理由を知りたいのですか?このエラーを修正する方法について説明します。
ありがとうございます!
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
// ...
@property (retain, nonatomic) User*user;
// ..
ドン:だから保持プロパティを作成することにより、AppDelegate
を変更
NSLog(@"I am in noticeDetailViewController:%@",user.realName);***//ERROR***
:あなたがそれにアクセスしようとする前に
User.h & User.m
@interface User : NSObject
{
NSString *realName;
NSString *userId;
}
@property (nonatomic, retain)NSString *realName;
@property (nonatomic, retain)NSString *userId;
- (id)initWithRealName :(NSString *)realNameArgument UserId :(NSString *)userIdArgument;
@end
@implementation User
@synthesize realName,userId;
- (id)initWithRealName :(NSString *)realNameArgument UserId :(NSString *)userIdArgument
{
self = [super init];
if (self)
{
realName = realNameArgument;
userId = userIdArgument;
}
return self;
}
- (void)dealloc
{
[super dealloc];
[realName release];
[userId release];
}
@end
:
もユーザーのinitメソッドを変更しますか? – NeverBe
イェップ、私はそれで確信しています。 – jxdwinter