我有一個滾動視圖,其中我添加了多個UIImageview的。如何刪除子視圖是UILabel
對於每個圖像視圖,我添加一個UIButton和一個UILabel。
現在我想刪除UILabel視圖。
請我的代碼中找到下面
- (void)viewDidLoad {
[super viewDidLoad];
int h;
for (h=0; h<3; h++) {
UIImageView *k=[[UIImageView alloc]initWithFrame:CGRectMake(h*40, 0, 60, 90)];
k.backgroundColor=[UIColor yellowColor];
k.tag=h;
UIButton *j=[[UIButton alloc]initWithFrame:CGRectMake(20, 20, 20, 20)];
[j addTarget:self action:@selector(ge:) forControlEvents: UIControlEventTouchUpInside];
j.backgroundColor=[UIColor redColor];
[k addSubview:j];
k.userInteractionEnabled=YES;
[self.view addSubview:k];
}
}
在這裏,我只是將圖像視圖和一個按鈕。如果標籤存在,刪除其他的UILabel添加的UILabel
一旦用戶點擊該按鈕
-(IBAction)ge:(id)sender{
UIImageView *imageView = (UIImageView *)[sender superview];
for (UIView *jkl in [[sender superview]subviews]) {
if ([jkl isKindOfClass:[UILabel class]]){
[jkl removeFromSuperview];
} else {
UILabel *y=[[UILabel alloc]initWithFrame:CGRectMake(20, 20, 20, 20)];
y.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Close.jpeg"]];
[imageView addSubview:y];
}
}
}
但的UILabel是沒有得到清除。你能幫忙嗎?