iphone - 如何删除以编程方式添加的自定义 View ?

标签 iphone objective-c ios

在其中一个 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/

相关文章:

iphone - scrollToRowAtIndexPath 不滚动到非事件/卸载的单元格

ios - 显示图像的特定部分

ios - 在新的 ViewController 上显示用户的帖子

iphone - 释放 UIWebView 后声音还在运行

iphone - UINavigationController 堆栈中的 UIViewController 方向更改

ios - NSURLSession 未到达服务器

ios - dlsym 无法从 CoreTelephony 悄悄加载

iPhone SDK 4.0 动画 block - 移动缩放 UIImage

iphone - 按升序对 NSDictionary 进行排序

objective-c - 两部相同的 iPhone,一部在 AVCaptureDeviceTypeBuiltInDualCamera 上返回 exc_bad_access