gpt4 book ai didi

ios - 在我想要的时候执行 segue

转载 作者:搜寻专家 更新时间:2023-11-01 06:04:53 25 4
gpt4 key购买 nike

晚上,我的 VC 中有 2 个节目转场。但我只想在我的 pickerView 有 row.count > 0 时触发这些 segues。

这是我的:

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

if segue.identifier == "searchImages" {

if pickerView.numberOfRows(inComponent: 0) > 0 {

let controller = (segue.destination) as! WebViewController
//replacing " " with "+" for google search queries
let type: WebViewController.SearchType = .image
let queryString = String(nameLabel.text!.characters.map {
$0 == " " ? "+" : $0
})
controller.searchType = type
controller.queryString = queryString
print("2")
}

}
if segue.identifier == "searchWiki" {

if pickerView.numberOfRows(inComponent: 0) > 0 {
let controller = (segue.destination) as! WebViewController
//replacing " " with "+" for google search queries
let type: WebViewController.SearchType = .wiki
let queryString = String(nameLabel.text!.characters.map {
$0 == " " ? "+" : $0
})
controller.searchType = type
controller.queryString = queryString
}
}
}

我知道我应该使用:ShouldperformSomething。但我不知道热用它。有什么建议吗?

最佳答案

你应该实现 shouldPerformSegue而不是在 prepareForSegue 方法中检查 pickerView.numberOfRows(inComponent: 0) > 0

P.S:Swift 3 代码(我假设这就是您想要的)。

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
return pickerView.numberOfRows(inComponent: 0) > 0
}

现在,prepareForSegue 方法应该类似于:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "searchImages" {
let controller = (segue.destination) as! WebViewController
//replacing " " with "+" for google search queries
let type: WebViewController.SearchType = .image
let queryString = String(nameLabel.text!.characters.map {
$0 == " " ? "+" : $0
})
controller.searchType = type
controller.queryString = queryString
print("2")

}

if segue.identifier == "searchWiki" {
let controller = (segue.destination) as! WebViewController
//replacing " " with "+" for google search queries
let type: WebViewController.SearchType = .wiki
let queryString = String(nameLabel.text!.characters.map {
$0 == " " ? "+" : $0
})
controller.searchType = type
}
}

希望这对您有所帮助。

关于ios - 在我想要的时候执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40219262/

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