I've a problem but lots of googling and SO posts did not help. In my iOS swift app, I have a tab bar controller with two tabs. When the user clicks on the second tab, the app switches to a second screen for creating an event. The user can switch between the two tabs freely. While on the second tab for creating an event, the user can add multiple candidate locations for the event. The way the user is able to add the locations should be through a map and I use MapKit. I use a push segue to send the user to a new UIViewController with a map inside it. When the user clicks the add location button, the map is shown properly (currently I didn't do any logic for interacting with the map). My problem is that, if the user clicks the back button (to dismiss the map screen) and try again to add location, the UIViewController will display a gray map and the app will hang at the line:
class AppDelegate: UIResponder, UIApplicationDelegate {
and the error message is :
Thread 1: EXC_BAD_ACCESS (code=1, address=0x103c)
#0 0x00699440 in EAGLContext_renderbufferStorageFromDrawable(EAGLContext*, objc_selector*, unsigned int, id<EAGLDrawable>) ()
I know that many SO posts talked about memory issues such as this SO post and I did try their solution but it didn't help.
This is the very simple code for my UIViewController that shows the map:
import UIKit
import MapKit
import ObjectMapper
import CoreLocation
class AddRestaurantViewController: UIViewController{
@IBOutlet weak var theMapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad();
println("viewDidLoad")
}
override func viewWillAppear(animated: Bool) {
println("viewWillAppear")
}
override func viewWillDisappear(animated: Bool) {
println("viewWillDisappear")
}
override func viewDidDisappear(animated: Bool) {
self.purgeMapMemory()
}
func purgeMapMemory(){
println("Now purging...")
self.theMapView.mapType = MKMapType.Standard
self.theMapView.removeFromSuperview()
self.theMapView = nil
}
}
Any hint?