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-18-2011, 01:36 AM   #1 (permalink)
Registered Member
 
marshusensei's Avatar
 
Join Date: Mar 2011
Location: Australia
Age: 28
Posts: 105
marshusensei is on a distinguished road
Default NSMutableDictionary - Adjusting name to load an image

Hello again!

I have a question, not sure the best way to word it. I'm trying to find a way to load a thumbnail version of an image that is set in a NSMutableDictionary.

In the NSMutableDictionary, I have:
Code:
@"test_image.jpg", @"image"
This is then called in the customise cell section:
Code:
    [[cell imageView] setImage:[UIImage imageNamed:[[[data objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"image"]]];
I would like it to load an image called

test_image_thumb.jpg

Is there a way I can add "_thumb.jpg" to the key?

Hmm, maybe this is too confusing.
__________________
Please visit - MushroomPudding.com
marshusensei is offline   Reply With Quote
Old 11-18-2011, 01:47 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You'll need to separate the image name using componentsSeparatedByString. Then use stringWithFormat to add "_thumb"

Code:
NSArray *imageNameComponents = [imageName componentsSeparatedByString:@"."];
NSString *thumbImageName = [NSString stringWithFormat:%@_thumb.%@", [imageNameComponents objectAtIndex:0], [imageNameComponents objectAtIndex:1]];
This code assumes you don't have any dots in your file names except for the file type. Also code is untested and method names are from memory so they might be off.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-18-2011, 10:16 AM   #3 (permalink)
Registered Member
 
marshusensei's Avatar
 
Join Date: Mar 2011
Location: Australia
Age: 28
Posts: 105
marshusensei is on a distinguished road
Default Cheers

Thanks Domelle!

I didn't think anyone would understand what I was trying to say, but you did! Thanks very much.
__________________
Please visit - MushroomPudding.com
marshusensei is offline   Reply With Quote
Old 11-18-2011, 10:33 AM   #4 (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 Domele View Post
You'll need to separate the image name using componentsSeparatedByString. Then use stringWithFormat to add "_thumb"

Code:
NSArray *imageNameComponents = [imageName componentsSeparatedByString:@"."];
NSString *thumbImageName = [NSString stringWithFormat:%@_thumb.%@", [imageNameComponents objectAtIndex:0], [imageNameComponents objectAtIndex:1]];
This code assumes you don't have any dots in your file names except for the file type. Also code is untested and method names are from memory so they might be off.
Domele's approach would work, but it would be "fragile". If the input filename included more than one period, it would not give the expected result. If it contained no periods, it would crash.

There are actually NSString methods specifically designed for dealing with file system paths. I would suggest using those instead:



Code:
NSString* firstPart = [imageName stringByDeletingPathExtension];
NSString* extension = [imageName pathExtension];
NSString *thumbImageName = [NSString stringWithFormat: "%@_thumb.%@", 
  firstPart, extension];
__________________
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 11-18-2011, 05:01 PM   #5 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Oh wow, I never knew those methods existed. Thanks for the info, I'll be using those methods from now on.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele 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: 402
17 members and 385 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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