我有一个名为 Post 的类,它是一个视图....我在我的主视图中添加了一些时间,如下所示:锁定如何从我的 self.view 中删除和释放这个对象....我只有这个类:
@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