2013-04-01 49 views
0

我添加了一些名爲* cellSeparator和其他UILabels的動態UIView ...現在發生什麼時,我再次調用此代碼,然後重寫標籤文本並覆蓋之前創建的標籤文本...我不是很瞭解這個IOS development.so誰能告訴我如何我可以再次動態創建之前刪除此UIView的?東陽UIView的是動態創建的,我不知道如何刪除的UIView如何刪除動態創建的UIView和UILabel文本?

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]; 
+0

當你第二次打電話時刪除超視圖的子視圖嗎? – Balu

+2

1.不是Xcode的問題,2.該類被稱爲'UIView',而不是'UIVIEW'。 – 2013-04-01 11:07:15

+0

要將哪個視圖添加該標籤和imageView –

回答

7

你可以寫一個方法來清除所有視圖的子視圖並根據您的需要修改此代碼。

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

Thanx ...解決了我的問題\ –