質問する
15115 次
2 に答える
30
あなたのcontainerView
プロパティは属性で宣言されていると思いますweak
。weak
プロパティの属性が必要な場合は、誰かがすでにそれを保持している必要があります。次に例を示します。
@property (nonatomic, weak) KGModalContainerView *containerView;
...
-(void)viewDidLoad {
[super viewDidLoad];
KGModalContainerView *myContainerView = [[KGModalContainerView alloc] initWithFrame:containerViewRect]; // This is a strong reference to that view
[self.view addSubview:myContainerView]; //Here self.view retains myContainerView
self.containerView = myContainerView; // Now self.containerView has weak reference to that view, but if your self.view removes this view, self.containerView will automatically go to nil.
// In the end ARC will release myContainerView, but it's retained by self.view and weak referenced by self.containerView
}
于 2013-02-27T10:48:05.237 に答える
3
Objective C の初心者としての私の 2 セント:
警告を与える行の右側、
[[KGModalContainerView alloc] initWithFrame:containerViewRect]
ヒープにオブジェクトを作成しますが、この時点では、このオブジェクトはどのポインターからも参照されていません。次に、このオブジェクトは に割り当てられself.containerView
ます。は弱いためself.myContainerView
、代入は右側で作成されたオブジェクトの参照カウントを増やしません。そのため、割り当てが完了してもオブジェクトの参照カウントは 0 のままであるため、ARC はすぐにオブジェクトを解放します。
于 2015-02-06T00:53:59.060 に答える