Ich benutze das Google Maps SDK und derzeit habe ich eine Karte, die den Benutzer von wo auch immer sie zu einem bestimmten Ort sind. Ich möchte, dass der Benutzer eingeben kann, wohin er möchte, anstatt immer an denselben Ort weitergeleitet zu werden. Ich habe der GUI ein Textfeld hinzugefügt und wenn ich die App im Simulator starte und auf das Textfeld klicke, erscheint keine Tastatur und es verhält sich so, als hätte ich sie nicht angetippt.Textfield funktioniert nicht einmal angeklickt im Simulator
Hier ist, wie ich mein Projekt ein:
import UIKit
import GoogleMaps
import GooglePlaces
import CoreData
class ViewController: UIViewController, CLLocationManagerDelegate, UITextFieldDelegate
{
let locationManager = CLLocationManager()
var currLocation: CLLocationCoordinate2D!
var keyy = "myKeyIsHere"
var didFindMyLocation = false
var count: Int = 0
var button = UIButton()
var latitude = UITextField()
var longitude = UITextField()
var path = GMSMutablePath()
super.viewDidLoad()
let blah = GMSCameraPosition.camera(withLatitude: 39.8282, longitude: -98.5795, zoom: 25.0)
mapView.camera = blah
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
mapView.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.new, context: nil)
currLocation = mapView.myLocation?.coordinate
button = UIButton(type: .system)
button.frame = CGRect(x: 135, y: 40, width: 100, height: 40)
button.backgroundColor = UIColor.clear
button.layer.cornerRadius = 5
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.blue.cgColor
button.setTitle("Route", for: UIControlState.normal)
button.addTarget(self, action: #selector(ViewController.buttonPressed), for: UIControlEvents.touchUpInside)
latitude = UITextField()
latitude.frame = CGRect(x: 5, y: 90, width: 175, height: 35)
latitude.backgroundColor = UIColor.white
latitude.layer.cornerRadius = 5
latitude.layer.borderWidth = 1
latitude.layer.borderColor = UIColor.black.cgColor
latitude.isUserInteractionEnabled = true
latitude.text = " Enter Latitude"
latitude.keyboardType = UIKeyboardType.numbersAndPunctuation
self.latitude.delegate = self
longitude = UITextField()
longitude.frame = CGRect(x: 195, y: 90, width: 175, height: 35)
longitude.backgroundColor = UIColor.white
longitude.layer.cornerRadius = 5
longitude.layer.borderWidth = 1
longitude.layer.borderColor = UIColor.black.cgColor
longitude.isUserInteractionEnabled = true
longitude.text = " Enter Longitude"
longitude.keyboardType = UIKeyboardType.numbersAndPunctuation
self.longitude.delegate = self
self.view.addSubview(latitude)
self.view.addSubview(button)
self.view.addSubview(longitude)
}
Es ist aber alles, was ich für das Problem relevant fühlen. Ich habe hier tatsächlich zwei Textfelder hinzugefügt, und beide funktionieren nicht! Bitte helfen Sie!
Art ein interessantes Problem. Testen Sie es in Ihrem Simulator? –
ive versucht mit dem Simulator, und auch mit meinem eigenen Telefon! – skyleguy
Da ich alle meine GUI-Elemente im View-Controller erstelle, sollte ich einfach das main.storyboard komplett löschen? – skyleguy