简体   繁体   English

UIView不会从超级视图中删除

[英]UIView is not removed from superview

I`m having problem with removing view from superview. 我在从超级视图中删除视图时遇到问题。 Adding 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];
        }
    }
}

Trying to remove: 尝试删除:

- (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];
        }
    }
}

But after touch view is still displaying. 但是触摸后仍然显示视图。 Tried to remove label (l) - it is removed 试图移除标签(l)-已移除

尝试这个,

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

You should store reference to this "unkillable" view in ivar or property. 您应该在ivar或property中存储对此“不可杀害”视图的引用。 Initialize it in first method and call removeFromSupperView in second. 在第一个方法中对其进行初始化,然后在第二个中调用removeFromSupperView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM