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 05-28-2010, 07:28 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 1
ChrisNZ is on a distinguished road
Default Creating a dynamic quantity of objects

Hi, I am trying to create a deck of cards (which itself is just a plain image) and when the user taps this deck, a new custom "Card" object is created. The "Card" object has a UIImageView along with some NSStrings which contain the card's type, suit etc...

How would I be able to create a new "Card" object for every tap of the deck? I do not know how many cards the user will want to draw from the deck so I cannot declare them in the .h file.

Thanks in advance
ChrisNZ is offline   Reply With Quote
Old 05-28-2010, 10:53 PM   #2 (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

You can store them all in an NSArray; that's a list of objects. This list can be of any length. The kind you want is probably an NSMutableArray; that's a mutable list that you can add and remove items from.

Code:
// make a pointer to an NSMutableArray, probably in your .h file
NSMutableArray *cardList; 

//Create the empty list and point the pointer
cardList = [[NSMutableArray alloc] init];


//create a card 
CardClass *myCard = [[CardClass alloc] init];

//put the card in the array (it gets retained by the array)
[cardList addObject:mycard];

//now we can release the card; it's safe in the array.
[myCard release];
You can get the cards back out by checking [cardList count] and calling [cardList objectAtIndex: n ];
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

Tags
card, game, iphone, uiimageview

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: 319
9 members and 310 guests
ajay123123, ashaman64, baja_yu, ChrisYates, HemiMG, newDev, Objective Zero, pkIDSF, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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