In this code I’m attempting to pass an array from one tab view to another using protocols. The method itself is a simple get method with one line returning an a mutableArray. Within it’s own class it works, within this class it is not even called.
- (void)viewDidLoad
{
[super viewDidLoad];
myLocationEntityArray = [[NSMutableArray alloc] initWithArray:[[self delegate] getMyLocationEntityArray]];
}
The header file for the class receiving the data:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@protocol CoreDataDelegate;
@interface ListTableViewController : UITableViewController
{
NSManagedObjectContext *managedObjectContext;
NSMutableArray *myLocationEntityArray;
id <CoreDataDelegate> delegate;
}
- (NSMutableArray *)fetchCoreData;
@property(nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property(nonatomic, assign) id <CoreDataDelegate> delegate;
@property(nonatomic, retain) NSMutableArray *myLocationEntityArray;
@end
@protocol CoreDataDelegate
//- (NSMutableArray *) fetchCoreData;
- (NSMutableArray *) getMyLocationEntityArray;
@end
The top of the header file sending the data:
@interface MapViewController : UIViewController <CLLocationManagerDelegate, CoreDataDelegate>
First you should change your procotol like this :
You set your
MapViewControllerto responds to your protocolCoreDateDelegate. So, I suppose you alloc yourListTableViewControllerinside theMapViewController. If that is the case, you need to do this :EDIT
Following your comments, here is a simpler way to do what you want.
NSNotification. It does not require protocol, and is easier to implement.In few words, when you will post the GetEntity notification in
MapViewController, it will call undirectly the-(void)getEntity:function ofListTableViewController