Prasad
Prasad

Reputation: 1914

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 = image;


[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?

Upvotes: 0

Views: 1564

Answers (4)

junaidsidhu
junaidsidhu

Reputation: 3580

there is the way, this code will help you out

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

    NSLog(@"%@",imgName);

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

Upvotes: 1

Raphael Petegrosso
Raphael Petegrosso

Reputation: 3870

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

Upvotes: 1

Maulik
Maulik

Reputation: 19418

There is no name. All you have is a UIImage object. That's it.

Upvotes: 0

Marcus Toepper
Marcus Toepper

Reputation: 2423

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

Upvotes: 0

Related Questions