tags:

views:

24

answers:

1

I'm using appDelegate for sharing NSMutableArray but it's crashing. Error message is unrecognized selector sent to instance

    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 NSMultableArray and already decleare in callAppDelegate.h. I already import callAppDelegate.h in top.

+2  A: 

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];
Manny
Yes, it's working. I need to add @synthesize AddItems;
saturngod
ayt, check out the [update] to avoid mem leak.
Manny