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-12-2011, 07:52 PM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 2
robbiecutting is on a distinguished road
Default using NSMutableArray

Hi,

First time posting to an online forum. Basically I've got a function, checkPileCardNum that iterates through calling another function populateArrayUpToPileCard until the function populateArrayUpToPileCard returns YES.

Each time populateArrayUpToPileCard is called it checks an NSArray of UIImages to see if the image associated with the index number passed into the array isEqual to the Image of a separate UIImageView, named pile. If the image is the same it returns YES and exits both the populateArrayUpToPileCard and checkPileCardNum function. If the image is different it initiates an NSMutableArray, called tempArray and adds the image to the array.

My aim is that the functions should create an Array of images up until the same image as the one used on the pile object, which I can then check another UIImage against to see if it is in the new array.

The function which calls the two other functions is called checkCardAgainstPile and I've setup a label to displays how many items are in the new tempArray. When I call it however it only populates 1 image and immediately afterwards returns YES.

The dealCards singleton class created works fine everywhere else in the application, it seems to be something in the populateArrayUpToPileCard function.

My code is attached below, any help whatsoever would be greatly appreciated.

- (void)checkCardAgainstPile
{
[self checkPileCardNum]; //call checkPileNum

int temp = [tempArray count];

NSString *cardStacktext = [[NSString alloc] initWithFormat: @"%d", temp]; //display number of items on UILabel
cardsInDeck.text = cardStacktext;
}

-(void)checkPileCardNum
{
for (int cardNum = 0; [self populateArrayUpToPileCard:cardNum] == YES; cardNum++) //iterate through calling populateArrayUpToPileCard each time, until (populateArrayUpToPileCard == YES)
{
[self populateArrayUpToPileCard:cardNum];
cardNum++;

[self checkPileCardNum];
}
}

-(BOOL)populateArrayUpToPileCard:(int)cardNum
{
if ([[[dealCards sharedDealData].deck objectAtIndex:cardNum] isEqual: [pile image]]) //check to see if image is the same as Pile image
{
return YES;
} else {
if (tempArray == nil) { //if not allocate tempArray
tempArray = [[NSMutableArray alloc] init];
}
[tempArray addObject:[[dealCards sharedDealData].deck objectAtIndex:cardNum]]; //add item to tempArray
return NO;
}
}

Last edited by robbiecutting; 05-12-2011 at 07:55 PM.
robbiecutting is offline   Reply With Quote
Old 05-12-2011, 08:51 PM   #2 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 2
robbiecutting is on a distinguished road
Default

Quote:
Originally Posted by robbiecutting View Post
-(BOOL)populateArrayUpToPileCard:(int)cardNum
{
if ([[[dealCards sharedDealData].deck objectAtIndex:cardNum] isEqual: [pile image]]) //check to see if image is the same as Pile image
{
return YES;
} else {
if (tempArray == nil) { //if not allocate tempArray
tempArray = [[NSMutableArray alloc] init];
}
[tempArray addObject:[[dealCards sharedDealData].deck objectAtIndex:cardNum]]; //add item to tempArray
return NO;
}
}
Is there a problem with my syntax in the populateArrayUpToPileCard function? I don't understand why it initially runs through the function from the else statement, i.e initialises the NSMutable array and adds the image and returns NO. Then after it exits the else statement goes instantly to the true statement and returns YES.

Could it be the populateArrayUpToPileCard function itself or the [self populateArrayUpToPileCard:cardNum] == YES conditional argument passed second on the for loop in the previous checkPileCardNum function? I'm new to XCode so I'm not to sure about the correct syntax/method.
robbiecutting is offline   Reply With Quote
Old 05-12-2011, 10:42 PM   #3 (permalink)
Knows SQL
 
iisword's Avatar
 
Join Date: Oct 2009
Location: Somewhere the streets are on fire, the sewers are flooded, and the cats are high on catnip
Posts: 529
iisword is on a distinguished road
Default

1) Since you're new here, I'm going to tell you to use the code tag from now on with your code. It makes it a lot easier to read for the rest of us.
2) Your for loop in checkPileCardNum calls the checkPileCardNum again within the loop, why are you doing that?
3)put an NSLog(@"Running in loop") in the for loop. Tell me if that fires.
__________________
iisword is offline   Reply With Quote
Reply

Bookmarks

Tags
isequal, nsarray, nsmutable array

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: 364
6 members and 358 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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