【发布时间】:2019-03-24 20:27:47
【问题描述】:
我正在尝试从 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 应用程序的一部分。很抱歉这个迟到的补充。不确定这是否会对答案产生影响。 任何帮助将不胜感激。
【问题讨论】:
-
如果您从情节提要加载了
UITableViewController,则需要将view出口初始化为UITableView。 -
那么我需要在storyboard中添加一个UITableView吗?
标签: ios swift uitableview swift4 uipickerview