MKMapView setregion swift -


i have mkmapview initiated in viewdidload:

override func viewdidload() {     super.viewdidload()         .....         let mapview = mkmapview(frame: view.bounds)         mapview.autoresizingmask = .flexibleheight | .flexiblewidth         mapview.delegate = self         view.addsubview(mapview)         view.sendsubviewtoback(mapview) 

and button:

@ibaction func findmepressed(sender: anyobject) {      .....     mapview.setregion(reg, animated: true) } 

i understand button isn't working because mkmapview declared in viewdidload. works fine in view it's linked storyboard. in view have initialise because of custom annotations won't work me reason. how link button viewdidload initialiser

you declared mapview local variable hence in scope in viewdidload method.

make mapview instance variable of viewcontroller:

class mapviewcontroller: uiviewcontroller, mkmapviewdelegate {     var mapview: mkmapview      override func viewdidload() {         super.viewdidload()             .....         self.mapview = mkmapview(frame: view.bounds)         self.mapview.autoresizingmask = .flexibleheight | .flexiblewidth         self.mapview.delegate = self         view.addsubview(self.mapview)         view.sendsubviewtoback(self.mapview)     }      ...      @ibaction func findmepressed(sender: anyobject) {         .....         self.mapview.setregion(reg, animated: true)     }  } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -