在情节提要中有5个按钮。如果我按下任何按钮,它将进入新的故事板。在新的情节提要中,我只想找到按下哪个按钮即可到达这里。
答案 0 :(得分:0)
您可以创建一个State
类,在其中可以设置由枚举表示的按钮类型。然后访问新情节提要中的值。
struct State {
static var btnType: ButtonType?
}
enum ButtonType {
case buttonA
case buttonB
// ..
}
在有按钮的主视图控制器中,在点击按钮时设置状态。
class ViewController: UIViewController {
func buttonADidTap(_ sender: Any) {
State.btnType = .buttonA
// display the other view controller, say MyVCA
}
func buttonBDidTap(_ sender: Any) {
State.btnType = .buttonB
// ..
}
}
在子视图控制器中,访问viewDidLoad
中的状态数据。
class MyVCA: UIViewController {
override func viewDidLoad() {
if let btnType = StateData.btnType {
switch btnType:
case .buttonA:
// ...
}
}
}
答案 1 :(得分:0)
将标签添加到按钮(在代码中或在情节提要中),然后将标签发送到按下按钮的下一个ViewController。
--amend
第二个ViewController
edit