gpt4 book ai didi

ios - 无法将类型 'MyAppName.ProfileController' 的值转换为 'MyAppName.SelectController'

转载 作者:行者123 更新时间:2023-11-30 12:03:08 26 4
gpt4 key购买 nike

我有一个带有 3 个按钮和一个步进器的 viewController

import UIKit
import AVFoundation

class HomeController: UIViewController {
var steppers : UIStepper?

static var globalLimit: Int = 0

@IBOutlet weak var hourLabel: UILabel!
@IBOutlet weak var stepper: UIStepper!

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc : SelectController = (segue.destination as? SelectController)! {
vc.limit = Int(stepper.value)
HomeController.globalLimit = Int(stepper.value)
}
if let np = segue.destination as? CourseController {
np.numberPlaces = Int(stepper.value)
}
}

我的应用程序在这里崩溃了:

if let vc : SelectController = (segue.destination as? SelectController)!

错误:

Could not cast value of type 'MyAppName.ProfileController' to 'MyAppName.SelectController'

之后,当我按下一个不是 SelectTapped 按钮的按钮时(在本例中我按下了配置文件按钮)。问题的原因是什么?我该如何解决?我预计有必要使用static var globalLimit

最佳答案

您正在强制转换并会产生错误。更改方法如下:

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

if let vc = segue.destination as? SelectController {
vc.limit = Int(stepper.value)
HomeController.globalLimit = Int(stepper.value)
}
if let np = segue.destination as? CourseController {
np.numberPlaces = Int(stepper.value)
}

}

关于ios - 无法将类型 'MyAppName.ProfileController' 的值转换为 'MyAppName.SelectController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46978121/

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