以Swift编程方式更改segue标识符名称

4
如何在编程中以编程方式更改特定segue的标识符名称?
我发现了这种方法,但对我没有用: SWrevealviewcontroller:从左到右切换滑动菜单方向 编辑:
我有一个名为SWreavealviewcontroller的菜单,并希望在英语情况下从左侧显示,在阿拉伯语情况下从右侧显示。

尝试这个:https://dev59.com/XVgR5IYBdhLWcg3wAJJK#41887007 - Harshal Valanda
1个回答

4

您不能通过编程方式更改segue名称。因为segue指定了应用程序故事板文件中两个视图控制器之间的转换,您可以在故事板中对其进行重命名。

您可以在视图控制器之间定义多个segue,并像这样通过编程方式调用segue:

performSegue(withIdentifier: "yourSegueID", sender: nil)

针对您的问题:
  1. You can create two segues between your view controllers, and give two different segue identifier names to them (eg. englishSegue and arabicSegue).
  2. Create a variable for your segue identifier. (You will use it to select which of your segue should be triggered.)
  3. Control your language in your view controller (eg. in your viewDidLoad function or where you should control it) programmatically and set your language variable as English or Arabic.
  4. After that you can trigger it anywhere you want it. For example in a button click:

    if (yourIdentifier == "English") {
        performSegue(withIdentifier: "englishSegue", sender: nil)
    } else if (yourIdentifier == "Arabic") {
        performSegue(withIdentifier: "arabicSegue", sender: nil)
    }
    

我想在同一个视图中拥有两个segue标识符,因为我有菜单SWreavealviewcontroller,并且我希望在英语语言环境下从左侧开始,在阿拉伯语言环境下从右侧开始。 - Amal El-galant
这个解决方案对我来说非常完美。我试图在Mac M1和M2上为iOS应用程序使用不同类型的过渡效果。这使我能够简单地调用相应的标识符。 - Jose Santos

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接