【问题标题】:Could not cast value of type 'UITableViewController'无法转换“UITableViewController”类型的值
【发布时间】:2019-07-18 15:20:45
【问题描述】:

我不断收到此错误消息

无法将“UITableViewController”类型的值转换为 SecondViewController

我真的不知道请帮忙

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     var destination = segue.destination as! SecondViewController
     destination.myString = outputName.text!
}

在“var”行上,但现在在覆盖“func line”上,我完全不知道这意味着什么。

【问题讨论】:

  • 表示 UITableViewController 不是 SecondViewController。你想移动到 SecondViewController 但改为移动到 UITableViewController
  • @AndreyChernukha 什么?
  • 我写的真的完全看不懂吗?
  • 所以我在 UItableview 中创建类以匹配 secondviewcontroller
  • 显示您的 SecondViewController 类的声明

标签: ios swift xcode segue


【解决方案1】:

所以我解决了!我在第二个 ViewController 上的课程标点错误,我忘记了大写 S

【讨论】:

  • 明天不能@AndreyChernukha
【解决方案2】:

为此

var destination = segue.destination as! SecondViewController

为避免崩溃,您需要在故事板假设中将类名 SecondViewController 设置为目标 vc

class SecondViewController:UITableViewController {}

【讨论】:

    【解决方案3】:
    class SecondViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate,UITableViewDelegate,UITableViewDataSource {
    

    我希望这会奏效。

    【讨论】:

      猜你喜欢
      • 2016-01-04
      • 1970-01-01
      • 2018-11-02
      • 2016-03-05
      • 2023-03-20
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多