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 11-26-2010, 12:38 PM   #1 (permalink)
Creator of From A to B
 
fudgie_no1's Avatar
 
Join Date: Nov 2010
Location: Wales
Posts: 45
fudgie_no1 is on a distinguished road
Question Convert UIButton.currentImage to NSString

Does anyone know how to achieve this? I can check the current image to see if it equals a string, but for the life of me I can't get the currentImage value to NSLog as a string?! Any help would be greatly appreciated.

Just to clarify, I want to get the current image filename from the UIButton (eg "image1.png")

Last edited by fudgie_no1; 11-26-2010 at 12:45 PM.
fudgie_no1 is offline   Reply With Quote
Old 11-26-2010, 12:56 PM   #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

Converting an image to text is a complex issue. Look into OCR software. I'm not sure if there's anything to support it in the SDK or if you would have to write your own. Or did you mean something else?
baja_yu is offline   Reply With Quote
Old 11-26-2010, 12:58 PM   #3 (permalink)
Creator of From A to B
 
fudgie_no1's Avatar
 
Join Date: Nov 2010
Location: Wales
Posts: 45
fudgie_no1 is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Converting an image to text is a complex issue. Look into OCR software. I'm not sure if there's anything to support it in the SDK or if you would have to write your own. Or did you mean something else?
Thanks but I don't want to convert the image into text. I literally just want to read the image that's on the button (ie "GoButton.PNG")??

Last edited by fudgie_no1; 11-26-2010 at 01:13 PM.
fudgie_no1 is offline   Reply With Quote
Old 11-26-2010, 01:11 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Once you create a UIImage from a file you can't check the filename/path. There's no such property on UIImage.

You should store the current image name in your "model" somehow - like saving the string when you set the image - instead of trying to tease it back out of the view.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 11-26-2010, 01:14 PM   #5 (permalink)
Creator of From A to B
 
fudgie_no1's Avatar
 
Join Date: Nov 2010
Location: Wales
Posts: 45
fudgie_no1 is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
Once you create a UIImage from a file you can't check the filename/path. There's no such property on UIImage.

You should store the current image name in your "model" somehow - like saving the string when you set the image - instead of trying to tease it back out of the view.
Really? Why would they make you do more work for something so simple??

I could do it the long way as follows:

if (SquareToCheck.currentImage == [UIImage imageNamed:@"Image1.PNG"]) {
MyImageAsString = @"Image1.PNG";
}

But then i'd have to code it for every image. surely there's a way I can just take the name of the image from the buttons currentimage property??
fudgie_no1 is offline   Reply With Quote
Old 11-26-2010, 01:40 PM   #6 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Yes really. The property currentImage is a UIImage, and it doesn't have a "name" or "path" property.

UIImage

By they way your method of checking if the address of one image is equal to another is dangerous. If a memory warning takes place then imageNamed: may start returning a different address for the same image. It will work some of the time as long as the image remains on the screen or doesn't get deallocated.

Apple doesn't make it easy because a UIButton/UIImage isn't a good place to store data. It should be usind to *display* data from some kind of model.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 11-26-2010, 02:32 PM   #7 (permalink)
Creator of From A to B
 
fudgie_no1's Avatar
 
Join Date: Nov 2010
Location: Wales
Posts: 45
fudgie_no1 is on a distinguished road
Question

Quote:
Originally Posted by smasher View Post
Yes really. The property currentImage is a UIImage, and it doesn't have a "name" or "path" property.

UIImage

By they way your method of checking if the address of one image is equal to another is dangerous. If a memory warning takes place then imageNamed: may start returning a different address for the same image. It will work some of the time as long as the image remains on the screen or doesn't get deallocated.

Apple doesn't make it easy because a UIButton/UIImage isn't a good place to store data. It should be usind to *display* data from some kind of model.
Hmmm, that does make sense I suppose. It promotes and ensures clean code.

Do you have any suggestions how I could check it otherwise? Would storing the images in an nsmutable array and comparing the UIButton.currentImage against that also be dangerous? The button will always be on the screen. Thanks for your advice.
fudgie_no1 is offline   Reply With Quote
Reply

Bookmarks

Tags
currentimage, nsstring

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: 375
7 members and 368 guests
HemiMG, Kirkout, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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