ios - UIView 未从 super View 中删除

标签 ios iphone uiview

我在从 super View 中删除 View 时遇到问题。 添加 View :

- (void)createCircles
{
    NSString *currentDate = [self currentDate];
    NSArray *array = [self.horizontalScroll subviews];
    UILabel *label = nil;
    for (label in array)
    {
        if ([label.text isEqualToString:currentDate])
        {
            UIView *view = [[UIView alloc] initWithFrame:label.frame];
            view.backgroundColor = [UIColor redColor];
            [self.horizontalScroll insertSubview:view atIndex:0];
            [self.labelsArray insertObject:view atIndex:0];
        }
    }
}

试图删除:

- (void)labelTouch:(UITapGestureRecognizer*)sender
{
    NSArray *array = [self.horizontalScroll subviews];
    UILabel *label = (UILabel*)sender.view;
    for (int i = 0; i < [array count]; ++i)
    {
        UILabel *l = array[i];
        if (label.tag == l.tag)
        {
            UIView *view = nil;
            view = [self.labelsArray objectAtIndex:0];
            view.hidden = YES;
            [view removeFromSuperview];
            view = nil;
            [self.labelsArray removeObjectAtIndex:0];
        }
    }
}

但触摸后 View 仍在显示。试图删除标签 (l) - 它已被删除

最佳答案

试试这个,

 [[[self.horizontalScroll subviews] objectAtIndex:0] removeFromSuperView];

关于ios - UIView 未从 super View 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21801302/

相关文章:

ios - 检测用户是否第一次在 iOS 中打开 View

php - IOS 向特定用户推送通知?

ios - MKMapView 没有正确过渡

ios - 即使在关闭 View Controller 后调用了 dealloc 方法,内存也没有被正确释放

swift - 混合程序化和 IB 设计时查看元素未显示

ios - 无法使用 Xcode 在模拟器中运行应用程序

ios - 异步函数返回正常,但数组变为空

iphone - 如何在屏幕顶部添加 UIToolbar?

ios - 覆盖非动态类声明

ios - 如何为 Core Data 中的二进制数据启用外部存储