2011-07-19 318 views
0

如何顯示圖像的名稱。如何獲取圖像的名稱

DetailCoverPage *detailCoverPage = [[DetailCoverPage alloc] initWithNibName:@"DetailCoverPage" bundle:nil]; 
detailCoverPage.coverPage = image; 


[self presentModalViewController:detailCoverPage animated:YES]; 
[detailCoverPage release]; 

在這裏,我需要得到像 imageName的名稱是字符串。 detailCoverPage.imageName = ???

如何獲取圖像的名稱?

+0

我在代碼中看不到圖像。 – Richard

+0

你可以給更多的代碼並描述它嗎?我們不能從你的代碼和你的代碼描述得出任何結論.. –

+1

這是一個重複的問題,請http://stackoverflow.com/questions/1740274/uiimageview-how-to-get-the-file-name-的最圖像分配 –

回答

0

IIRC,你不能。一旦圖像被初始化,它就不會將它的名字一併記錄下來。您必須將其存儲在單獨的成員中。 HTH Marcus

0

沒有名字。你所擁有的只是一個UIImage對象。而已。

1

有沒有辦法使用UIImage做到這一點。一種方法來解決這個問題,如果你真的需要它會被繼承的UIImage並添加name屬性:

UINamedImage.h

#import <Foundation/Foundation.h> 


@interface UINamedImage : UIImage { 

} 

@property (nonatomic, readonly) NSString * name; 

-(UINamedImage *) initWithName:(NSString *)name; 

@end 

UINamedImage.m

@implementation UINamedImage 

@synthesize name = _name; 

-(UINamedImage *) initWithName:(NSString *)name { 
    UIImage * image = [UIImage imageNamed:name]; 
    self = [super initWithCGImage:image.CGImage]; 
    _name = [name retain]; 
    return self; 
} 

-(void) dealloc { 
    [_name release]; 
    [super dealloc]; 
} 

@end 
1

存在的方式,此代碼將幫助您解決問題

NSString *imgName = [self.imgView1st image].accessibilityIdentifier; 

    NSLog(@"%@",imgName); 

    [self.imgView2nd setImage:[UIImage imageNamed:imgName]];