Ios 如何删除动态创建的UIView和UILabel文本?

Ios 如何删除动态创建的UIView和UILabel文本?,ios,uiview,Ios,Uiview,我正在添加一些名为*cellSeparator的动态UIView和其他UILabels…现在发生的是,当我再次调用此代码时,它将重写标签文本并覆盖以前创建的标签文本…我对此ios开发不太了解。因此,有人能告诉我如何在创建之前动态删除此UIView吗再次?因为UIView是动态创建的,所以我不知道如何删除该UIView UILabel *indexLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size

我正在添加一些名为*cellSeparator的动态UIView和其他UILabels…现在发生的是,当我再次调用此代码时,它将重写标签文本并覆盖以前创建的标签文本…我对此ios开发不太了解。因此,有人能告诉我如何在创建之前动态删除此UIView吗再次?因为UIView是动态创建的,所以我不知道如何删除该UIView

  UILabel *indexLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-150, self.view.frame.size.width/2,30)];
            [indexLabel setBackgroundColor:[UIColor clearColor]];
            indexLabel.textColor = [UIColor whiteColor];
            indexLabel.text = @"Details:-";
            indexLabel.font = [UIFont systemFontOfSize:20.00];
            UILabel *tagLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-120, self.view.frame.size.width/2, 30)];
            tagLabel.backgroundColor = [UIColor clearColor];


            NSLog(@"LOg %@",imageId);
            NSLog(@"LOg %@",imageStyle);
            NSLog(@"LOg %@",imageType);
            NSLog(@"LOg %@",imageWeight);
            tagLabel.text = [NSString stringWithFormat:@"The Id of Jewl Is:  %@",imageId];

            imageTypelabel= [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-90, self.view.frame.size.width/2, 30)];
            imageTypelabel.backgroundColor = [UIColor clearColor];
            imageTypelabel.text = [NSString stringWithFormat:@"The Type of Jewl Is:  %@",imageType];
            imageStylelabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-60, self.view.frame.size.width/2, 30)];
            imageTypelabel.backgroundColor = [UIColor clearColor];
            imageStylelabel.text = [NSString stringWithFormat:@"The style of Jewl Is:  %@",imageStyle];
            imageWeightlabel = [[UILabel alloc] initWithFrame:CGRectMake(20, self.view.frame.size.height-30, self.view.frame.size.width/2, 30)];
            imageStylelabel.backgroundColor = [UIColor clearColor];
            imageWeightlabel.text = [NSString stringWithFormat:@"The weight of Jewl Is:  %@",imageWeight];
            imageWeightlabel.backgroundColor = [UIColor clearColor];
            imageWeightlabel.textColor = [UIColor whiteColor];
            imageTypelabel.textColor = [UIColor whiteColor];
            imageWeightlabel.textColor = [UIColor whiteColor];
            tagLabel.textColor = [UIColor whiteColor];
            UIImage *imageBegin = [UIImage imageNamed:imageName];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:imageBegin];


            UIView *cellSeparator = [[UIView alloc] initWithFrame:CGRectMake(0,545, self.view.frame.size.width ,3)];
            cellSeparator.tag=1;
            [cellSeparator setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
             UIViewAutoresizingFlexibleRightMargin | 
             UIViewAutoresizingFlexibleWidth];       
            [cellSeparator setContentMode:UIViewContentModeTopLeft];    
            [cellSeparator setBackgroundColor:[UIColor whiteColor]];
            [self.view addSubview:cellSeparator]; 

您可以编写一个方法来删除视图的所有子视图,并根据需要修改此代码

- (void)removeSubviewsOfView
{
    NSArray *subViews = [self.view subviews];
    for(UIView *view in subViews)
    {
        [view removeFromSuperview];
    }
}

第二次调用时删除superview的子视图?1。不是一个Xcode问题,2。该类称为UIView,而不是UIView。要将标签和imageView添加到哪个视图