ios - 如何为 View Controller 中的单个按钮创建两个 segue?

标签 ios iphone swift

我有一个 Root View Controller ——它是一个呈现给用户的简单页面。在此页面中,有一个转到用户配置文件页面的 UIBarButton。

当用户在其配置文件中时,他/她将有一个后退按钮,允许他/她返回到 Root View Controller 。

但是, Root View Controller 对于管理员和客户是不同的(管理员有一个标准 View Controller ,客户有一个标准 View Controller )。

如何创建两个由“后退”配置文件按钮触发的转场?我的意思是,根据当前登录的用户(管理员或客户),我想返回到他们各自的页面。

客户端无法返回到管理员页面,反之亦然。

有什么方法可以创建这两个转场吗?甚至另一种/更好的方法?我曾尝试使用 Storyboard来做到这一点,但是当我创建第二个 segue 时,它​​会删除链接到按钮的第一个。

最佳答案

你不能那样做,但还有其他方法,创建两个 segue bwtween SenderViewControllerDestinatrionViewController。之后为您的按钮设置操作并根据您的要求执行 segue。

@IBAction func buttonAction(_ sender: UIButton) {
    if condition {
        self.performSegue(withIdentifier: "identifier1", sender: nil)
    }
    else {
        self.performSegue(withIdentifier: "identifier2", sender: nil)
    }
}

关于ios - 如何为 View Controller 中的单个按钮创建两个 segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42812757/

相关文章:

iphone - PhoneGap 2.7在状态栏中显示事件指示器

iphone - 实现 NSURLRequest、NSURLConnection 和 NSURLRequestReturnCacheDataElseLoad 策略

ios - 将 JSON 数组反序列化为对象的 Swift 数组

arrays - Swift - 带数组的字典 - 获取对数组的引用

iphone - 如何在 iPhone 中解析 gdata xml?

swift - iOSDropDown : Type 'UIResponder' has no member 'NSNotification'

ios - 我安排一个计时器使用 readRSSI 函数读取 RSSI,但是当我的应用程序进入后台时计时器停止

ios - 移除 iOS 的限制

ios - InstagramKit 集成到 swift 项目中

iphone - 如何更改 UISearchbar 取消按钮的文本颜色