2011-04-30 74 views
0
myImageView = [[UIImageView alloc] initWithImage:[imagearray objectAtIndex:j]]; 
     [myImageView setUserInteractionEnabled:YES]; 
     [myImageView setTag:i]; 

     if (i==0||i==1) { 

      [UIImageView beginAnimations:nil context:NULL]; 
      [UIImageView setAnimationDuration:1.5]; 
      [UIImageView setAnimationRepeatCount:0]; 
      myImageView.center=CGPointMake(42+t, 220+y); 
      [self.view addSubview:myImageView]; 
      NSLog(@"my imageviw tag %d",myImageView.tag); 
      [myImageView release]; 
      t=t+10; 
      y=y+10; 
     } 
+0

如果你描述你为什么要找到图片的名字,你可能会得到一个替代的解决方案也许你问题。 – Devraj 2011-04-30 06:39:15

+0

检查我的答案:[如何从imageview中获取imagename](http://stackoverflow.com/questions/1740274/uiimageview-how-to-get-the-file-name-of-the-image-assigned/20700384# 20700384) – 2013-12-20 09:34:32

回答

0

我仍然不完全理解你的question..If你想从UIImageView的图像文件名对象是不可能..

的原因是一个UIImageView 实例不存储的图像文件。它存储一个显示UIImage 实例。当你从 制作一个文件时,你可以这样做:

UIImage * picture = [UIImage imageNamed:@“myFile.png”];一旦这个 完成后,不再有任何 引用文件名。 UIImage 实例包含数据,无论它在何处获得它。因此,UIImageView不可能知道文件名称 。

此外,即使你可以,你也会从 从视图中获取文件名信息。 这打破了MVC。

this thread..Credit的答案,他

0

无耻复制没有办法,如果从UIImageView的图像文件,以获得名。但是你可以做一件事情 - 当你用图像名称初始化图像视图时,你可以在数组中添加该图像名称,然后将该数组索引设置为uiimageview对象的标记值。现在,当你想获得图像文件名时,你可以发现使用该数组,你只需要从uiimageview中获取标签值,并从数组中获取该标签的文件名。

希望它会帮助!

0

这个代码将会帮助你

- (NSString *) getFileName:(UIImageView *)imgView{ 

    NSString *imgName = [imgView image].accessibilityIdentifier; 

    NSLog(@"%@",imgName); 

    return imgName; 

} 

以此为:

NSString *currentImageName = [self getFileName:MyIImageView]; 
+0

它返回null! – 2013-06-12 13:34:47