子视图不会从superview中删除

时间:2014-11-11 22:43:22

标签: ios objective-c

我试图根据选择的行删除一组子视图,但是当调用该方法时,只有第一个if语句可以正常工作,if(firstRowSelected)

子视图在第一行中标记为10及以上,第二行标记为50及以上,第三行标记为100及以上。我不明白什么是错的,因为除了一些变量之外,if体内的代码是相同的。

- (void) resetLane{
    if (firstRowSelected) {
        for(UIView *subview in [self.view subviews]) {
            if (subview.tag >= 10 && subview.tag < 50) {
                currentCardL1 = 10;
                sipLabel.text = [NSString stringWithFormat:@"Sips: %d", sipCount];
            [UIView animateWithDuration:.4
                                  delay:.1
                                options: UIViewAnimationOptionCurveEaseInOut
                             animations:^{
                                 animationPlaying = YES;
                                 CGRect f = CGRectMake(0, 180, 71, 96);
                                 subview.frame = f;

                             }completion: ^(BOOL finished){
                                 [subview removeFromSuperview];
                                 sipCount += 1;
                                 cDisplayedL1 = 0;

                             }];
            }
        }
        [self dealNewCard];

    }else if (secondRowSelected) {
        for(UIView *subview in [self.view subviews]) {
            if (subview.tag >= 50 && subview.tag < 100) {
                currentCardL2 = 10;
                sipLabel.text = [NSString stringWithFormat:@"Sips: %d", sipCount];
                [UIView animateWithDuration:.4
                                      delay:.1
                                    options: UIViewAnimationOptionCurveEaseInOut
                                 animations:^{
                                     animationPlaying = YES;
                                     CGRect f = CGRectMake(0, 180, 71, 96);
                                     subview.frame = f;

                                 }completion: ^(BOOL finished){
                                     [subview removeFromSuperview];
                                     sipCount += 1;
                                     cDisplayedL2 = 0;
                                 }];
            }
        }
        [self dealNewCard];

    }else if (thirdRowSelected) {
        for(UIView *subview in [self.view subviews]) {
            if (subview.tag >= 100 && subview.tag < 150) {
                NSLog(@"imgage with tag %ld removed", (long)subview.tag);
                currentCardL3 = 100;
                sipCount += 1;
                sipLabel.text = [NSString stringWithFormat:@"Sips: %d", sipCount];
                [UIView animateWithDuration:.4
                                      delay:.1
                                    options: UIViewAnimationOptionCurveEaseInOut
                                 animations:^{
                                     animationPlaying = YES;
                                     CGRect f = CGRectMake(0, 180, 71, 96);
                                     subview.frame = f;

                                 }completion: ^(BOOL finished){
                                     [subview removeFromSuperview];
                                     cDisplayedL3 = 0;
                                 }];
            }
        }

        [self dealNewCard];
    }
}

0 个答案:

没有答案