UIView在删除UIImageView后没有更新

时间:2014-06-22 11:14:21

标签: ios objective-c uiview uiimageview uiimage

我的屏幕上有4个以上的图像。每张图片都有id,然后将图片ID分享给电子邮件。从视图中删除任何图像后,我仍然获得所有图像ID,包括删除图像ID。如何在没有删除图像ID的情况下获取更新图像ID。

     mmageView=[[UIImageView alloc]initWithFrame:CGRectMake(200,200,350,199)];
          ageView setUserInteractionEnabled:YES];


                [mmageView setImageWithURL:[NSURL URLWithString:[productimg_array objectAtIndex:[sender tag]-1]] placeholderImage:nil options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {


                }];

                NSLog(@"Tag %d",[sender tag]);

                [mmageView setTag:[sender tag]-1];


                ObjectAddedToScreen *object = [[ObjectAddedToScreen alloc] init];
                object.productDescription = [descript_array objectAtIndex:[sender tag]-1];
                object.view = mmageView;
                [self.objectsAddedToScreen addObject:object];

object.object_sku=[sku_array objectAtIndex:[sender tag]-1];

              [self.view addSubview:mmageView];

使用Longpress删除图像:

-(void)dblongPress:(UILongPressGestureRecognizer*)sender{

 CGPoint tapLocation1 = [sender locationInView: self.view];
            for (UIImageView *imageeView1 in self.view.subviews) {
                if (CGRectContainsPoint(imageeView1.frame, tapLocation1)) {

                    // [imageeView1 removeFromSuperview];

                    [imageeView1 setHidden:YES];


}
                }
            }

1 个答案:

答案 0 :(得分:1)

BTW隐藏不等于删除:P

试试这样。

NSArray *subViewsArray = self.view.subviews;
    CGPoint tapLocation1 = [sender locationInView: self.view];

    for(UIView *v in subViewsArray){
        if([v isKindOfClass:[UIImageView class]])
        {
            UIImageView *imageView = (UIImageView *)v;{
                if (CGRectContainsPoint(imageView.frame, tapLocation1)){

                    [imageView removeFromSuperview];
                }
            }
        }
    }