【发布时间】:2015-05-22 08:16:09
【问题描述】:
我有一个简单的视图控制器,里面有一个 MKMapView 对象,以这种方式定义:
类声明:
@interface GeoViewController : UIViewController <MKMapViewDelegate>
@property (nonatomic, strong) MKMapView* viewMap;
@end
实施:
@implementation GeoViewController
- viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
viewMap = [[MKMapView alloc] init];
MKCoordinateRegion worldRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
[viewMap setRegion:worldRegion animated:YES];
viewMap.pitchEnabled = YES;
viewMap.showsUserLocation = YES;
viewMap.delegate = self;
[self.view addSubview:viewMap];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
viewMap.showsUserLocation = NO;
self.viewMap.delegate = nil;
[self.viewMap removeFromSuperview];
}
- (void)resizeForOrientation:(BOOL)isLandscape withFrame:(CGRect)frame {
[super resizeForOrientation:isLandscape withFrame:frame];
const CGRect fullFrame = CGRectMake(0, 0, frame.size.width, frame.size.height);
viewMap.frame = fullFrame;
}
@end
我第一次展示视图控制器的工作原理。然后我在我的应用程序中导航,如果我回到 GeoViewController,就会崩溃:
- 控制台上没有消息错误
- main.m 已打开并报告“线程 1:EXC_BAD_ACCESS”
-
在调试导航器(左)我收到关于线程 1 的错误报告:
EAGLContext_renderbufferStorageFromDrawable(EAGLContext*, objc_selector*, unsigned int, id)
现在,谷歌搜索了很多,我找不到适合我的解决方案:
我也尝试过 viewDidDisappear,但没办法
[EAGLContext setCurrentContext:nil];
这一行似乎崩溃了:
viewMap.frame = fullFrame;
任何建议将不胜感激!
更新
我在测试中有时会收到其他错误:
检测到opengl线程冲突
【问题讨论】:
-
可能不相关,但由于
viewMap是一个属性,您应该使用self.viewMap = ...分配它,而不仅仅是viewMap = ...。所以viewMap = [[MKMapView alloc] init];应该是self.viewMap = [[MKMapView alloc] init];。
标签: ios objective-c iphone opengl-es mapkit