gpt4 book ai didi

ios - 转场和转场条件不起作用

转载 作者:行者123 更新时间:2023-11-28 09:23:18 24 4
gpt4 key购买 nike

我正在开发一款天气应用,它既利用核心位置,又依靠用户输入来查找特定位置的天气预报。问题是 segues 不起作用,根据我所做的研究,我还实现了一种我不希望 segues 通过的方法,但它们似乎不起作用,我无法弄清楚为什么他们不工作。

import UIKit
import CoreLocation
import SVProgressHUD

class ViewController: UIViewController, CLLocationManagerDelegate {

var locationManager: CLLocationManager?
var currentLocation: CLLocation?
@IBOutlet weak var zipCodeTextField: UITextField!
let store = CoordinatesDatastore.sharedInstance
var userInputLocationSuccess: Bool?
var coreLocationSuccess: Bool?

override func viewDidLoad() {
super.viewDidLoad()
SVProgressHUD.setDefaultMaskType(.black)
}

override func viewWillAppear(_ animated: Bool) {
self.zipCodeTextField.text = ""
self.currentLocation = nil
self.userInputLocationSuccess = false
self.coreLocationSuccess = false
}

//Core location button and I wanted to explicitly have the user press this button.

@IBAction func getMyLocationWeatherTapped(_ sender: UIButton) {
self.locationManager = CLLocationManager()
self.locationManager?.delegate = self
self.locationManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters
self.locationManager?.requestWhenInUseAuthorization()
self.locationManager?.requestLocation()
}

@IBAction func goButtonTapped(_ sender: Any) {
SVProgressHUD.show(withStatus: "Finding Your Location")
if let userText = self.zipCodeTextField.text{
GoogleCoordinateAPIClient.isAddressValid(zipCode: userText) { (boolValue) in
if boolValue == true {
self.userInputLocationSuccess = true
DispatchQueue.main.async {
SVProgressHUD.dismiss()
self.presentAlert("Valid Input", message: "Found Forecast", cancelTitle: "OK")
self.performSegue(withIdentifier: "goButtonSegue", sender: self)
}
}
else if boolValue == false {
SVProgressHUD.dismiss()
self.userInputLocationSuccess = false
self.presentAlert("Invalid Input", message: "Please re-enter valid input", cancelTitle: "OK")
}
}
}
}

func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
print("ENTERED INTO THE SEGUE FUNCTION")
if segue.identifier == "goButtonSegue"{
if let destinationVC = segue.destination as? WeatherForecastViewController {
guard let neededZipcode = self.zipCodeTextField.text else {print("neededZipcode did not unwrap"); return}
destinationVC.zipCode = neededZipcode
}
}
else if segue.identifier == "coreLocationButtonSegue"{
if let destinationVC = segue.destination as? WeatherForecastViewController {
guard let userLocation = currentLocation else {print("did not pass user location"); return}
destinationVC.coordinateHolder = currentLocation
}
}
}

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "coreLocationButtonSegue"{
if self.coreLocationSuccess == true && self.currentLocation != nil {
return true
}
}
else if identifier == "goButtonSegue"{
if self.userInputLocationSuccess == true && self.zipCodeTextField.text != nil {
return true
}
}
return false
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
SVProgressHUD.show(withStatus: "Finding your location")
if self.currentLocation == nil {
SVProgressHUD.dismiss()
if let personCoordinates = locations.first{
self.currentLocation = personCoordinates
self.coreLocationSuccess = true
self.presentAlert("Location Found", message: "Your Location was found", cancelTitle: "OK")
self.performSegue(withIdentifier: "coreLocationButtonSegue", sender: self)
}
}
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse {
self.locationManager?.startUpdatingLocation()
}
else if status == .notDetermined || status == .denied || status == .restricted {
self.locationManager?.requestWhenInUseAuthorization()
}
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
SVProgressHUD.dismiss()
presentAlert("Location Not Found", message: "Provide zipcode, address or city", cancelTitle: "OK")
self.shouldPerformSegue(withIdentifier: "coreLocationButton", sender: self)
}
}

segues 没有传递信息,也没有在指定的条件下正常工作。

最佳答案

您的 prepare(for segue:sender) 函数的方法签名错误,因此它没有被调用。

这方面的一个线索是您没有 override 关键字,并且编译器不会对此报错。

你应该:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) 

注意 Any?AnyObject?

关于ios - 转场和转场条件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50321836/

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