简体   繁体   中英

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

尝试这个,

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

You should store reference to this "unkillable" view in ivar or property. Initialize it in first method and call removeFromSupperView in second.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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