在其中一个 iPad 应用程序中,我正在工作,我已将自定义 View 添加到 View 中。这工作正常,但现在我想删除所有添加的自定义 View 。我该怎么做?
以下是我添加自定义 View 的代码
for (int col=0; col<colsInRow; col++) {
// NSLog(@"Column Number is%d",col);
x=gapMargin+col*width+gapH*col;
//self.styleButton=[[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];
ComponentCustomView *componentCustomobject=[[ComponentCustomView alloc] initWithFrame:CGRectMake(x, y, width, height)];
componentCustomobject.backgroundColor=[UIColor redColor];
componentCustomobject.componentLabel.text=[appDelegate.componentsArray objectAtIndex:row];
[self.formConatinerView addSubview:componentCustomobject];
tempCount1++;
}
最佳答案
您可以从父 View 中删除所有类型为 ComponentCustomView 的 subview
for (UIView *view in self.formConatinerView.subviews) {
if ([view isKindOfClass:[ComponentCustomView class]) {
[view removeFromSuperview];
}
}
关于iphone - 如何删除以编程方式添加的自定义 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11223715/