0

2つのクラスAとBがあります。AではBのオブジェクトを作成し、BIではクラスAのback Buttonプロパティにアクセスしています。Bでは、Aを弱参照変数として宣言しています。コードはクラッシュすることなく正常に実行されます。ただし、実装でメモリリークが発生しているかどうかはわかりません。また、Aで弱参照としてbackButtonを宣言する必要がありますか?

@interface A : UIViewController
{

    IBOutlet UIButton *backButton;
    B * cntrl;

}

@property (nonatomic, strong) UIButton *backButton;

// Here is the implementation of A
@implementation A
@synthesize backButton;

// pushing to B
cntrl = [[B alloc]initWithNib:nil bundle:nil];
cntrl.parent = self;
[self.navigationController pushViewController:cntrl animated:YES];


@interface B:UIViewController
{
    A __weak *parent;
}

@implementation

-(void)method
{

parent.backButton.enable = NO;
[self.navigationController popViewControllerAnimated:YES];
}
4

1 に答える 1

1

いいえ、コードは問題ありません。疑問がある場合は、機器を使用してアプリをテストできます。

于 2012-09-20T08:06:52.627 に答える