NSInvalidArgumentException: *** -[NSPlaceholderString initWithFormat:locale:arguments:]: nil argumen
- by BU
I have no idea where in my code is causing this problem. Can someone please take a look and let me know what I am missing? The code is relatively straightforward.
+(void)processGetGameOffersByGameWithReply:(NSDictionary *)responseDictionary
{
GameOffer *gameOffer;
@try
{
SharedResources *s = [SharedResources instance];
GameOffersByGameTableViewController *gameOffersByGameTableViewController = [s gameOffersByGameTableViewController];
NSMutableArray *gameOffersArray = [gameOffersByGameTableViewController gameOffersAsArray];
NSString *dealsCountString = [[responseDictionary valueForKey:@"number_of_deals"] retain];
NSNumber *dealsCount = [[SharedResources convertToNumberFromString:dealsCountString] retain];
int i=0;
NSString *keyStringForTitle;
NSString *title, *description, *keyStringForDescription;
for(int i=0; i < dealsCount; i++)
{
/*NSString *keyStringForDealID = [NSString stringWithFormat:@"DealID%d", i];
NSString *DealIDString = [responseDictionary valueForKey:keyStringForDealID];
NSNumber *DealID = [[SharedResources convertToNumberFromString:DealIDString] retain];*/
keyStringForTitle = [[NSString alloc] initWithFormat:@"Title%d",i] ;
title = [[NSString alloc] initWithFormat:[responseDictionary valueForKey:keyStringForTitle]];
//[[responseDictionary valueForKey:keyStringForTitle] retain];
keyStringForDescription = [[NSString alloc] initWithFormat:@"Description%d", i];
description = [[NSString alloc] initWithFormat:[responseDictionary valueForKey:keyStringForDescription]];
/*NSString *keyStringForGameID = [NSString stringWithFormat:@"GameID%d", i];
NSString *GameIDString = [responseDictionary valueForKey:keyStringForGameID];
NSNumber *GameID = [[SharedResources convertToNumberFromString:GameIDString] retain];*/
gameOffer = [[GameOffer alloc] initWithTitle:title Description:description Image:nil];
//int i =0;
SharedResources *s = [SharedResources instance];
[gameOffersArray addObject:[gameOffer retain]];
int j=0;
}
NSString *temp = nil;
int k = 0;
//find the navigation controller
UINavigationController *myNavigationController = [[s gamesTableViewController] navigationController];
//push the table view controller to the navigation controller;
[myNavigationController pushViewController:gameOffersByGameTableViewController animated:YES];
}
@catch (NSException *ex)
{
NSLog(@"Count is %d", [[[[SharedResources instance] gameOffersByGameTableViewController] gameOffersAsArray] count]);
NSLog(@"\n%@\n%@", [gameOffer Title], [gameOffer Description] );
[SharedResources LogException:ex];
}
}
The problem is whenever the program gets done with the for loop, it doesn't execute the "NSString *temp=nil" anymore, it jumps to the catch statement.
I tried removing the for loop setting i = 0. The problem doesn't occur anymore. It reaches teh end of the method by adding only one object in the array. The problem only occurs if there's a for loop.
In the catch statement, even with the error, I can see that the array is filled properly and the [gameOffer Title] and [gameOffer Description] have the correct values.
Thanks so much for your help.