How to get the name of the image
How to show the name of the image.
DetailCoverPage *detailCoverPage = [[DetailCoverPage alloc] initWithNibName:@"DetailCoverPage" bundle:nil];
detailCoverPage.coverPage = imag开发者_如何学Pythone;
[self presentModalViewController:detailCoverPage animated:YES];
[detailCoverPage release];
here i need to get the name of the image imageName is string. detailCoverPage.imageName=???
how to get the name of the image?
There is no way to do it using UIImage. One way to solve this problem if you really need it would be subclassing UIImage and adding a name attribute:
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
there is the way, this code will help you out
NSString *imgName = [self.imgView1st image].accessibilityIdentifier;
NSLog(@"%@",imgName);
[self.imgView2nd setImage:[UIImage imageNamed:imgName]];
IIRC, you can't. Once the image is initialized, it doesn't take it's name along on the ride. You'd have to store it in a separate member instead. HTH Marcus
There is no name. All you have is a UIImage object. That's it.
精彩评论