ios - 如果 selectedSegmentIndex 不同,则 ViewController 不同
问题描述
我的代码是
@IBAction func pressedButton(_ sender: Any) {
self.resignFirstResponder()
if mySegment.selectedSegmentIndex == 0 {
在这里我需要如果我在ViewControllerA上选择 Segment #0 (并按下我的按钮)然后转到ViewControllerB,如果是 Segment #1 然后是ViewControllerC,如果是 Segment #2 然后是ViewControllerD。
是否可以?
解决方案
是的,您可以在 IB 中为他们设置 ID,如果您使用UINavigationController
或呈现,则推送
if mySegment.selectedSegmentIndex == 0 {
let so = self.storyboard?.instantiateViewController(withIdentifier: "AID")
self.navigationController?.pushViewController(so!, animated: true)
}
else if mySegment.selectedSegmentIndex == 1 {
let so = self.storyboard?.instantiateViewController(withIdentifier: "BID")
self.navigationController?.pushViewController(so!, animated: true)
}
推荐阅读
- flutter - 如何使用颤振更改首选网络类型
- python - Pygnuplot 导出到 Excel 图表
- java - 使用 JAVA 中的 LDAP,如何设置 Kerberos AES 支持复选框对应于名为 msDS-SupportedEncryptionTypes 的属性中设置的值?
- reactjs - 数据不会被拉入前端 - 做出反应
- powershell - Set-ADObject:实例对象的对象类必须包含'top'
- python - Pyspark:如何创建新列并将列的值条件与行值匹配
- java - Spring MVC 与 Spring Boot 与 Spring
- html - 隐藏内容显示并向下滚动时,Chrome 页面会跳转/闪烁
- angular - 禁用 ngx-bootstrap 弹出窗口?
- swift - 如何获取通知权限状态(Swift)?