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];
}