最后尝试我[self.mapVIEw removeOverlays:self.mapVIEw.overlays];它仍然不起作用.任何想法如何删除这些叠加?
谢谢.
更新1
我有错误:malloc:***错误的对象0x5adc0c0:指针被释放没有分配
***在malloc_error_break中设置一个断点来进行调试
我想我知道为什么,但不知道如何解决它?
以下是我需要在mapVIEw上绘制另一行的代码:
// Create a c array of points. MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D) * 2);// Create 2 points.MKMapPoint startPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(oldLatitude,oldLongitude));MKMapPoint endPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(newLatitude,newLongitude));// Fill the array.pointsArray[0] = startPoint;pointsArray[1] = endPoint;// Erase polyline and polyline vIEw if not nil.if (self.routeline != nil) { [_routeline release]; self.routeline = nil;}if (self.routelineVIEw != nil) { [_routelineVIEw release]; self.routelineVIEw = nil;}// Create the polyline based on the array of points.self.routeline = [MKpolyline polylineWithPoints:pointsArray count:2];// Add overlay to map.[self.mapVIEw addOverlay:self.routeline];// clear the memory allocated earlIEr for the points.free(pointsArray);// Save old coordinates.oldLatitude = newLatitude;oldLongitude = newLongitude;
所以我释放了以前的叠加层的routeline对象.所以当我试图删除它,它崩溃,因为它已被释放.
以下是用于添加重叠式视图的mapVIEw代理的代码:
- (MKOverlayVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForOverlay:(ID <MKOverlay>)overlay{ MKOverlayVIEw* overlayVIEw = nil; if(overlay == _routeline) { // If we have not yet created an overlay vIEw for this overlay,create it Now. if(self.routelineVIEw == nil) { self.routelineVIEw = [[[MKpolylineVIEw alloc] initWithpolyline:_routeline] autorelease]; self.routelineVIEw.fillcolor = [UIcolor bluecolor]; self.routelineVIEw.strokecolor = [UIcolor bluecolor]; // Size of the trace. self.routelineVIEw.linewidth = routelinewidth; } overlayVIEw = self.routelineVIEw; } return overlayVIEw;}
如果你们知道如何解决这个问题,从MKMapVIEw中删除所有的叠加层就会很棒!
更新2
我试图没有释放我的routeline和routelineVIEw对象,它现在工作.似乎也没有泄漏.所以现在我这样做:
// Erase polyline and polyline vIEw if not nil.if (self.routeline != nil) { //[_routeline release]; self.routeline = nil;}if (self.routelineVIEw != nil) { //[_routelineVIEw release]; self.routelineVIEw = nil;}解决方法 当您调用removeOverlays:时,地图视图将释放MKOverlay和MKOverlayVIEw对象.
您在_routeline和_routelineVIEw中持有您自己的引用.
removeOverlays:被调用后,变量将指向已经释放的内存.当您重新创建折线时,您将被过度释放,从而导致崩溃.
所以删除释放调用:
if (_routeline != nil) { [_routeline release]; // <-- remove this self.routeline = nil;}if (_routelineVIEw != nil) { [_routelineVIEw release]; // <-- remove this self.routelineVIEw = nil;}总结
以上是内存溢出为你收集整理的iOS删除MKMapView覆盖不起作用全部内容,希望文章能够帮你解决iOS删除MKMapView覆盖不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)