-1

I'm using appDelegate for sharing NSMutableArray but it's crashing. Error message is:

unrecognized selector sent to instance

My code is:

countrydata *countryobj=(countrydata *)[listItems objectAtIndex:indexPath.row];

if(addItems==nil)
{
    addItems=[[NSMutableArray alloc]init];
}
[addItems addObject:countryobj];

callAppDelegate *appDelegate = (callAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.AddItems=addItems;

[self dismissModalViewControllerAnimated:YES];

Where is my code is wrong? appdelegate.AddItems is NSMutableArray and already declare in callAppDelegate.h. I already import callAppDelegate.h in top.

Cœur
  • 37,241
  • 25
  • 195
  • 267
saturngod
  • 24,649
  • 17
  • 62
  • 87
  • Which line does the error occur on? That error message means you are sending a message to an object which does not have that message declared. Possible memory leak with addItems there as well btw – willcodejavaforfood Oct 05 '10 at 07:28
  • appDelegate.AddItems=addItems; is error occur. I can't parse the value to appDelegate. – saturngod Oct 05 '10 at 07:29
  • 3
    Your variable and class naming-"scheme" is really confusing. Some of your variables start with capital letters and some with small letters. The same applies to your class-names. This will get you in big trouble if your projects start to grow. – Matthias Bauch Oct 05 '10 at 07:40
  • Totally agree with fluchpunkt, suggest you read some best practices about programming :) – Manny Oct 05 '10 at 07:41

1 Answers1

2

If the error occurred at appDelegate.AddItems=addItems then you might have forgotten to synthesize it.

You should add
@synthesize AddItems;
after @implementation in your *appDelegate.m

This assumes that you've already declared it @property (nonatomic, retain / assign) in your header file (.h)

[update] Minor comment if you did declare it as @property (nonatomic, retain) then you should release addItems after setting it to a retained property because it will cause memory leak.

E.g.

appDelegate.AddItems=addItems;
[addItems release];
CTSchmidt
  • 1,155
  • 3
  • 17
  • 30
Manny
  • 6,277
  • 3
  • 31
  • 45