在 tableview cellForRowAtIndexPath 中,我执行以下操作:
MapViewController *mapView = [[MapViewController alloc] initWithCoordinates:city.Latitude longitude:city.Longitude];
[cell addSubview:mapView.view];
//[mapView release]; -- will crash here
调用最后一行会给出此内存错误 EXC__BAD _ACCESS”。如何在不崩溃的情况下释放我分配的上述内存?
从上面看,cell 是一个 UITableViewCell。
MapViewController 是一个 UIViewController,它实现了 MKReverseGeocoderDelegate 和 MKMapViewDelegate。在 MapViewController 的 init 中,它分配了一个 MKMapView。在控制器的 viewDidLoad 中,它将 mapview 添加到 UIViewController 的视图中:
[self.view addSubview:mapView];