ios - 如何检测哪个 segue 标识符激活了当前 View Controller

标签 ios objective-c segue

我只是在寻找一种方法来检测哪个 Segue 标识符激活了当前的 viewController。我需要这样做,因为我有可能不满足的条件,但可以从另一个 viewController 引用,然后我想使用该特定的 segue ID 突出显示一些标签。以前有人需要这样做吗?你是如何处理这个问题的?

最佳答案

可能你应该在你的“当前 View Controller ”上创建一个属性来存储 segue 的名称,然后在使用 segue 实例化你的“当前 View Controller ”的 Controller 上你在触发 segue 执行之前分配它:

objective-c :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"YourSegueName"]) {

    // Get destination view
    CurrentVC *vc = [segue destinationViewController];

    // Get button tag number (or do whatever you need to do here, based on your object
    vc.segueName = @"YourSegueNam";
}}

swift 3:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "YourSegueName"
    {
        if let destinationVC = segue.destination {
            destinationVC.segueName = segue.identifier
        }
    }
}

这是你需要的吗?让我知道。 无论如何,我仍然不知道你为什么要那样做。

关于ios - 如何检测哪个 segue 标识符激活了当前 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45195562/

相关文章:

android - 使用移动浏览器(Unity webgl)时如何强制横向模式?

iOS 7 游戏中心在模拟器而不是设备上运行

objective-c - iOS 存储和缓存存储限制

swift - 来自 UICollectionView ReusableView(标题)的 Popover segue

ios - 关闭 SearchBar 上的自动建议

ios - swift 改变颜色的属性观察器

ios - #define 指令上的这个错误是什么?

ios - 有没有一种有效的方法来创建大量 GMSMarker 对象?

ios - 使用 TableView 继续

Swift 项目在 Facebook 登录后无法正确继续