所以我有3个视图控制器,将其命名为:与定制类iOS的对象 - 视图初始化一次
- Dashboard
- Map
- Location List
在MapVC,我附上1个大UIView的定制类XMapView的。在XMapView里面我有这样的代码
- (id)initWithFrame:(CGRect)aRect {
if ((self = [super initWithFrame:aRect])) {
[self commonInit];
}
return self;
}
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
[self commonInit];
}
return self;
}
- (void)commonInit{
UIView *mapView = [[[NSBundle mainBundle] loadNibNamed:@"XMapView"
owner:self
options:nil] objectAtIndex:0];
mapView.frame = self.bounds;
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview: mapView];
}
所以基本上MapVC刚刚注入XmapView并显示它。
我在MapVC控制器此代码。请注意,我已将MapVC中的自定义类视图替换为.h文件。
//.h file
@property (strong, nonatomic) IBOutlet XMapView *mapStoreView;
//.m file
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
// this following code will load the Map from the XMapView to the MapVC
[self.mapStoreView loadMap:self.results viewController:self selectedOutletFromList:self.selectedOutletFromList];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.mapStoreView removeFromSuperview];
self.mapStoreView = nil;
self.mapStoreView.mkMapView.delegate = nil;
[self.mapStoreView.mkMapView removeAnnotations:self.mapStoreView.mkMapView.annotations];
self.results = nil;
}
顺序为仪表板 - > MapVC - >位置列表
测试用例:
1. Dashboard -> MapVC, map will load.
2. MapVC -> Location List -> MapVC, map will not load.
3. Dashboard -> MapVC -> Dashboard -> MapVC, map will always load.
什么问题?这里我错过了什么吗?
你为什么[self.mapStoreView removeFromSuperview] self.mapStoreView = nil;你是从插座做出的,并且你没有再次分配。所以它没有显示。请勿删除此 –
,因为您在viewDidDisappear中重新映射。 – KKRocks
如果它没有显示,为什么当我从仪表板到MapVC时加载? – Alvin