首先,你应该改变你的网络协议是这样的:
#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
头文件发送数据的顶部:
@protocol CoreDataDelegate
//- (NSMutableArray *) fetchCoreData;
- (void) getMyLocationEntityArray:(NSMutableArray *)entityArray;
@end
你设置你的MapViewController
以响应你的协议CoreDateDelegate
。所以,我想你可以在MapViewController
内分配你的ListTableViewController
。如果是这样的话,你需要做的是:
// MapViewController.m
...
ListTableViewController *listVC = [[ListTableViewController alloc] init];
listVC.delegate = self;
// display your listVC
...
// Somewhere in your code of MapViewController.m
- (void) getMyLocationEntityArray:(NSMutableArray *)entityArray {
// do something with entityArray
}
编辑
按照你的意见,这里是你想要做什么简单的方法。 NSNotification
。它不需要协议,更容易实现。
// In ListTableViewController.m
// In Init or viewDidLoad function
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getEntity:)
name:@"GetEntity"
object:nil];
- (void)getEntity:(NSNotification *)notif {
NSArray *entityArray = (NSArray *)[notif object];
// do something with entityArray
}
// In dealloc or viewDidUnLoad function
[[NSNotificationCenter defaultCenter] removeObserver:self
name:@"GetEntity"
object:nil];
// In MapViewController.m
// theEntityArray to be defined
[[NSNotificationCenter defaultCenter] postNotificationName:@"GetEntity"
object:theEntityArray
userInfo:nil];
在几句话,当你将发布GetEntity通知,MapViewController
,它会undirectly调用ListTableViewController
的
-(void)getEntity:
功能'达到viewDidLoad'时已经设置委托?我敢打赌它是零。 – DarkDust你在哪里分配代表?你确定self.delegate不是零,当你问它的位置实体数组? – jrturton
我该如何设置?我怀疑这可能是问题,并试图self.delegate =自我,但有一个错误告诉我这两种类型是不兼容的。 – Deco