故事板“Main”中带有标识符“UIViewController-ZWG-5q-24I”的实例化视图控制器,但没有获得UITableView。

问题描述 投票:0回答:1

我试图从UIPickerView选择到UITableViewController。当用户选择一年时,应该转到UITableView以显示给定年份的驾驶员排名列表。我遇到的问题是UINavigationController不是rootViewController。因为我以编程方式生成UITableViewController。如果那时我知道我会在AppDelegate中实现这个代码

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
     window?.makeKeyAndVisible()
     window?.rootViewController = UINavigationController(rootViewController: StandingTableViewController())
    return true
}

这是不正确的,因为这将直接到UITableViewController。下面是UIPickerView的代码。

extension seasonViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return seasons.count
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return seasons[row]
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    selectedSeason = seasons[row]
    seasonTextField.text = selectedSeason
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "getStanding" {
        let standingVC = segue.destination as! StandingTableViewController

        standingVC.standing = seasonTextField.text!

    }
}

这是TableViewController的代码。

class StandingTableViewController: UITableViewController {

var standing = ""
let SEASON_URL = "https://ergast.com/api/f1"

var champions: [DriverStanding] = []
override func viewDidLoad() {
    super.viewDidLoad()
    navigationController?.title = standing

    fetchJSON(standing: standing)

}

我试图避免在故事板中这样做。或者我是否必须在这个实例中的故事板中创建UITableView?只是为了让您知道UIPickerView是TabView应用程序的一部分。对不起这个迟到了。不确定这是否会对答案产生影响。 Storyboard layout任何帮助将不胜感激。

ios swift uitableview swift4 uipickerview
1个回答
0
投票

从你的图像看起来你在故事板中使用普通的UIViewController并设置他StandingTableViewController类,这是UITableViewController的子类。

因此你得到正常的UIView而不是UITableView作为view

要修复它,删除故事板中的控制器并添加新的UITableViewContoller,并将他的类设置为StandingTableViewController

© www.soinside.com 2019 - 2024. All rights reserved.