클래스 게시와 해당보기가 있습니다. 내 기본보기에서 다음과 같이 몇 번 추가합니다. 잠그기이 객체를 제거하고 해제하는 방법보기에서 유형 객체를 제거하고 놓습니다.
@interface Post : UIView{
UILabel * label1;
UILabel * label2;
UILabel * label3;
}
@implementation Post
-(void)init
{
self = [super init];
if (self) {
label1 = [[UILabel alloc]init];
label2 = [[UILabel alloc]init];
label3 = [[UILabel alloc]init];
label1.frame = CGRect(10,10,100,30);
label2.frame = CGRect(10,60,100,30);
label3.frame = CGRect(10,110,100,30);
}
return self;
}
@end
이 메인 클래스 컨트롤러
@implementation HomeViewController
-(void)viewDidLoad{
Post *p = [[Post alloc]init]
p.frame = CGRect(0,0,0,320,460);
p.backgroundColor = [UIColor blue];
[self.view addsubview: p];
[p release];
Post *p2 = [[Post alloc]init]
p2.frame = CGRect(0,0,0,320,460);
p2.backgroundColor = [UIColor blue];
[self.view addsubview:p2];
[p2 release];
Post *p3 = [[Post alloc]init]
p3.frame = CGRect(0,0,0,320,460);
p3.backgroundColor = [UIColor blue];
[self.view addsubview:p3];
[p3 release];
}
-(void)RemoveAllPosts
{
//How to remove and release all post from self.view???
}
@end
'- (void) dealloc { [label1 release]; [label2 release]; [label3 release]; }'Post' 클래스의 Paramasivan이 질문에 대답했습니다 –
오오오! 릴리스 전에 내 자신에 의해 내 개체 게시 내가 dealloc 오른쪽에서 릴리스 할 필요가 없었어요? 다음과 같이 보입니다 : [p.label1 release]; [p.label2 release]; [p.label3 release]; [피 릴리스]; –
이상한 코딩을 할 수 있지만 dealloc은 할당 된 객체를 해제하는 가장 좋은 장소입니다 –