gpt4 book ai didi

ios - 在模拟器中单击后文本字段不起作用

转载 作者:行者123 更新时间:2023-11-28 16:04:12 25 4
gpt4 key购买 nike

我正在使用 Google Maps SDK,目前我有一张 map ,可以将用户从任何地方引导到特定位置。我希望用户能够输入他们想去的地方,而不是总是被路由到同一个位置。我在 GUI 中添加了一个文本字段,每当我在模拟器中运行该应用程序并单击该文本字段时,都不会出现键盘,就好像我没有点击它一样。

这是我设置项目的方式:

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)
}

还有更多,但我认为这与问题相关。我实际上在这里添加了两个文本字段,但都不起作用!请帮忙!

最佳答案

您需要从 Storyboard或编程方式启用您的文本字段的控制状态,如下所示。

enter image description here

 latitude.isEnabled = true
longitude.isEnabled = true

更新:

注意:将所有代码移动到 viewDidLoad? 中,如下所示

 override func viewDidLoad() {
super.viewDidLoad()
}

尝试使用以下方法之一启用 textField。当 textField 开始编辑时...

  func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
print("textFieldShouldBeginEditing:")
return true
}

func textFieldDidBeginEditing(_ textField: UITextField){
print("textFieldDidBeginEditing:")
}

关于ios - 在模拟器中单击后文本字段不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40535832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com