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 Tutorials > Tutorial Requests

Reply
 
LinkBack Thread Tools Display Modes
Old 05-04-2011, 04:16 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Location: Canterbury
Posts: 7
Nosleep is on a distinguished road
Default Random Image

Hi, complete noob seeks help here.

I'm trying to create an app that at the push of a button gets an image from a url, the image would be random from a selection that I've uploaded. I've managed to get it to get 1 image from a url how would i go about making it's selection random.

Thank you in advance!
Nosleep is offline   Reply With Quote
Old 05-04-2011, 05:26 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

to generate a random number between 0 and X use

Code:
int yourRandomNumber = arc4random() % X;
__________________
dany_dev is offline   Reply With Quote
Old 05-05-2011, 02:29 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2011
Location: Canterbury
Posts: 7
Nosleep is on a distinguished road
Default

Thank you for the help! Something I also need help with is building the array from which i would get the images as I'm getting some errors, I followed another tutorial on here about getting random urls from an array but it wasn't that helpful for a newcomer myself!

I appreciate that this is probably very annoying but we were all noobs once right? Thanks in advance!
Nosleep is offline   Reply With Quote
Old 05-06-2011, 04:19 AM   #4 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

create your array like
Code:
NSMutableArray *yourArray = [NSMutableArray arrayWithObjects:@"link1", @"link2", @"link3", @"link4", @"link5", @"link6", nil];
extract 1 link randomly, and download\show it.

Code:
int yourRandomNumber = arc4random() % yourArray.count;

NSString *myLink = [yourArray objectAtIndex:yourRandomNumber];
__________________
dany_dev is offline   Reply With Quote
Old 05-09-2011, 10:40 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2011
Location: Canterbury
Posts: 7
Nosleep is on a distinguished road
Default

Thank you very much!
Nosleep is offline   Reply With Quote
Old 05-10-2011, 06:34 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2011
Location: Canterbury
Posts: 7
Nosleep is on a distinguished road
Default

I am still running into some errors. Here is my .m file :

-(IBAction)showImage;
{ theimageview.image= [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://i1197.photobucket.com/albums/aa425/nosleepdev/4.png"]]];


NSMutableArray *yourArray = [NSMutableArray arrayWithObjects:
@"http://i1197.photobucket.com/albums/aa425/nosleepdev/1.jpg", @"http://i1197.photobucket.com/albums/aa425/nosleepdev/2.gif", @"http://i1197.photobucket.com/albums/aa425/nosleepdev/3.gif", @"http://i1197.photobucket.com/albums/aa425/nosleepdev/4.png", @"link5", @"link6", nil];




{
int yourRandomNumber = arc4random() % yourArray.count;

NSString *http;http:////i1197.photobucket.com/album...sleepdev/4.png = [yourArray objectAtIndex:yourRandomNumber];

} < The errors are both related to this, "Label at the end of compound satement" and "Expected Statement" As well as this I'm getting yellow flagged regarding unused variables "http" and "yourRandomNumber" If you could just explain where I'm going wrong I would greatly appreciate it!

I apologise in advance as I understand this must be very tedious and the problem is probably very obvious. Thank you for helping and thanks for being patient with me.
Nosleep is offline   Reply With Quote
Old 05-12-2011, 03:14 PM   #7 (permalink)
Registered Member
 
Join Date: Apr 2011
Location: Canterbury
Posts: 7
Nosleep is on a distinguished road
Default

Anyone, any help here?
Nosleep 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: 437
17 members and 420 guests
ahmedozcan, baja_yu, Droverson, iAppDeveloper, ipodphone, JoeRCruso, karatebasker, laureix68, LunarMoon, PapaSmurf, Paul Slocum, peterwilli, pipposanta, Rudy, SLIC, SuperDietGenius, vogueestylee
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,696
Threads: 94,139
Posts: 402,962
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jasper_muc
Powered by vBadvanced CMPS v3.1.0

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