मैं आईपैड के लिए अपने पहले स्विफ्ट एप्लिकेशन पर काम कर रहा हूं। इस प्रकार मेरे पास नीचे टूलबार में एक बटन के साथ एक मूल मानचित्रदृश्य है, जिसे मैं रीफ्रेश करना चाहता हूं और क्लिक करने के बाद उपयोगकर्ता स्थान पर ध्यान केंद्रित करना चाहता हूं।मानचित्र बटन रीफ्रेश स्थान
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var location: CLLocation!
let locationManager = CLLocationManager()
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var refresh: UIBarButtonItem!
@IBAction func refresh(sender: AnyObject) {
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.mapView.setRegion(region, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// location delegate methods
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Error code: " + error.localizedDescription)
}
}
मैं कैसे ताज़ा करें बटन यह करने के लिए प्राप्त कर सकते हैं:
वर्तमान में मैं इस कोड है? मैं वास्तव में कुछ मदद की जरूरत के रूप में मैं स्विफ्ट/xcode :)
धन्यवाद करने के लिए नया हूँ
मुझे यकीन नहीं है कि मैं आपको सही तरीके से समझ गया हूं। आप केवल नियंत्रक को कार्रवाई क्यों नहीं करते हैं और अपनी सेवाओं/प्रबंधकों में डेटा रीफ्रेश करते हैं? – razor118
मैं यह क्षमा करने के बारे में कैसे जाऊं? मैं वास्तव में xcode के लिए नया हूं :(@ razor118 मैं – Oscar