Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-08-2011, 09:34 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 1
d4apple is on a distinguished road
Default retrieving image name on UIButton

how can i retrieve name that i have already set on a UIButton .. I m not asking how to set image but how to retrieve it . Plz assist
d4apple is offline   Reply With Quote
Old 09-08-2011, 09:38 AM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Images don't have names. You'll need to keep track of it somewhere else, in an instance variable or possibly subclass UIImage.
baja_yu is offline   Reply With Quote
Old 09-08-2011, 10:22 AM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by d4apple View Post
how can i retrieve name that i have already set on a UIButton .. I m not asking how to set image but how to retrieve it . Plz assist

As baja_yu pointed out, images don't have names. An image can come from a variety of sources. They are not always loaded from a file.

If you are using the UIButton method setImage:forState: to set the button image yourself, with code something like this:

[myButton setImage:
[UIImage imageNamed: @"image.png"]
forState: UIControlStateNormal];

Then you might want to create a custom subclass of UIButton that has a new method, setImageToFileName, and a new string property imageFileName. Something like this:


The header for your custom button class:

Code:
@class myButton: UIButton
{
  NSString* imageFileName;
}

@property (nonatomic, readonly) NSString* imageFileName;

- (BOOL) setImageToFileName: (NSString*) newFileName;
@end
The .m file for your custom button class:
Code:
//Create a private category of the class that allows 
//us to change the imageFileName

@interface myButton()
@property (nonatomic, copy) NSString* imageFileName;
@end

@implementation myButton


@synthesize imageFileName;

- (BOOL) setImageToFileName: (NSString*) newFileName;
{
  self.imageFileName = newFileName;
  if ([self.imageFileName && [self.imageFileName length] >0)
    [self setImage: 
      [UIImage imageNamed: self.imageFileName]
      forState: UIControlStateNormal];
}

//...
@end

Then, when you use one of these custom buttons, you can use its imageFileName property to figure out the filename that was last used as the button image. Note that the code above would not set up the imageFileName for the initial image that is set in Interface Builder. I don't know of a way to do that, since by the time the program runs, the filename is no longer available. You'd need to set the image filename by calling your setImageToFileName in code in your ViewDidLoad method.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-08-2011, 12:56 PM   #4 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

@DuncanC You left a bracket at the beginning of the if statement that shouldn't be there.
iSDK is offline   Reply With Quote
Old 09-08-2011, 01:14 PM   #5 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Depending on what you are actually doing and where you need these names, it might be good to subclass UIImage by adding the imageName property, instead of the button. That way you can tie a name to the image of a UIImageView and any other place you use images, even arrays of images etc.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
9 members and 376 guests
apatsufas, JackReidy, jeroenkeij, Sami Gh, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:55 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0