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-13-2011, 03:07 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 59
duvdev is on a distinguished road
Default how to CONCATENATE elements?

Hello,
Lets say for example I have 20 buttons called:

button1
button2
.
.
button20

now I want to load different image to every button and I want to use a for loop:

for (index=1; index<21; index++){

load image to buttonX

where ButtonX is equal to button CONCATENATE with index value so if index=5
i will have button5 = ....
and I will be able to load the images.

how it can be done?

thanks,
Shlomi
duvdev is offline   Reply With Quote
Old 09-13-2011, 03:10 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Put all of your buttons in an NSArray. Then you can access a particular button by using the objectAtIndex: method of the array in your for loop.
smithdale87 is offline   Reply With Quote
Old 09-13-2011, 03:17 PM   #3 (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

You could give your buttons different tags and use viewWithTag, but an NSArray might be a cleaner approach, faster, and there's no chance of two view objects having the same tag and potentially crashing your app.
baja_yu is offline   Reply With Quote
Old 09-13-2011, 03:41 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 59
duvdev is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
Put all of your buttons in an NSArray. Then you can access a particular button by using the objectAtIndex: method of the array in your for loop.
I am having a lot of trouble with NSArray.I tried to generate a NSMutableArray
that will store the data permanently and I will be able to get the data frome everywhere in the code but i just wont do it.
duvdev is offline   Reply With Quote
Old 09-13-2011, 03:43 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

We can't help you without more details. Post the code, describe the problem, did you get crashes? If so, post the crash log from the console, do you get compiler errors or warnings? If so, post the exact message and the line on which you get it. Does your code not do what you want? If so, what does it do and what did you expect it to do.
baja_yu is offline   Reply With Quote
Old 09-13-2011, 04:09 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 59
duvdev is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
We can't help you without more details. Post the code, describe the problem, did you get crashes? If so, post the crash log from the console, do you get compiler errors or warnings? If so, post the exact message and the line on which you get it. Does your code not do what you want? If so, what does it do and what did you expect it to do.
Hi, thanks for the fast answer.
I can't post the code now because I and away from the mac computer.
but i can provide some info:
I need a vector ( array ) of random numbers 1 to 20 without duplicates.
so with the help from Duncan from this forum I creates a NSMutableArray wit numbers from 1 t 20. then I used a function to scramble the order of the numbers in the array. so far so good.


now I want to be able to save this array and to able to get the numbers by for loop. the problem is when I use an if statement all the data in the array is lost.

Is it possible to copy a Mutable array NSArray?
I tried to make the NSMutableArray to be a "global" but it ain't working.

If some one have an example of how to make Array to operate as global it will be grate.

Thanks,
Shlomi
duvdev is offline   Reply With Quote
Old 09-13-2011, 04:14 PM   #7 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

yea you're definitely gonna need to post the code, you're doing something sketchy. Also, how did we get from buttons to randomly generated numbers in an array?
smithdale87 is offline   Reply With Quote
Old 09-13-2011, 04:24 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 59
duvdev is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
yea you're definitely gonna need to post the code, you're doing something sketchy. Also, how did we get from buttons to randomly generated numbers in an array?
it was just a small question that i thought that will solve the problem.
I will post the code tomorrow.
duvdev 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: 408
15 members and 393 guests
7twenty7, Eclectic, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, JackReidy, jarv, sacha1996, teebee74, tim0504, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
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 05:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0