-2

我的图像视图中有一些图像,滚动视图中有图像名称,现在我想在单击图像时删除图像和相关名称......只需单击图像,图像名称应该被删除,图像也会被删除。

我的代码在这里......

-(void)imageViewTapped:(UITapGestureRecognizer*)sender
{
    bool isFound = FALSE;
    NSInteger foundIndex=0;
    NSInteger index = sender.view.tag;
    NSMutableDictionary *currentObject = [dataArray objectAtIndex:index];
    NSLog(@"id 1: %@", [currentObject objectForKey:@"_ID"]);
    for (NSMutableDictionary *object in nameDAtaArray)
    {
    NSInteger currentId = [[object objectForKey:@"_ID"] intValue];
        NSLog(@"id 2: %d", currentId);
        if([[currentObject objectForKey:@"_ID"] intValue] == currentId)
        {
            ++point;

            isFound = TRUE;
            NSLog(@"view tag...%d",sender.view.tag);
            [sender.view removeFromSuperview];

            };
            break;
        }
        foundIndex++;
    }
    if(!isFound)
    {

        point--;
    }
    else
    {
        [nameDAtaArray removeObjectAtIndex:foundIndex];
        [self showNameLabelInScrollView];
        [nameContainerScrollView setNeedsDisplay];
    }
    [self showpointlabel];
}

thanks in advance..
4

1 回答 1

0
-(void)scrollViewsingleTappedInScrollMethod:(UITapGestureRecognizer *)recognizer{

       imageview = (UIImageView *)recognizer.view;

      //we select the image using tag.(contain many images)
    if ([imageview tag] == 100) {

         NSFileManager *fileManager = [NSFileManager defaultManager];
   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,   YES);
   NSString *documentsDirectory = [paths objectAtIndex:0];
   NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:
                      [NSString stringWithFormat:@"%@.png", fileName]];

   NSError *error = nil;
   if(![fileManager removeItemAtPath: fullPath error:&error]) {
      NSLog(@"Delete failed:%@", error);
   } else {
      NSLog(@"image removed: %@", fullPath);
   }

   NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];    
   NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);


        }

        }

如果你只隐藏然后只设置Alpha。像,imageview.alpha = 0;

于 2013-10-05T16:36:47.257 回答