一旦执行停止 performseguewithidentifier

stop performseguewithidentifier once executed

我有这段代码可以使用信标更新距离。

func updateDistance(distance: CLProximity) {
    UIView.animateWithDuration(0.8) {
        switch distance {
        case .Unknown:
            print("unknown")
        case .Far:
            print("far")
        case .Near:
            print("near")
        case .Immediate:
             print("Immediate")
             self.performSegueWithIdentifier("beaconSegue", sender: self)
        }
    }
}

我只想问一下,如果 self.performSegueWithIdentifier 函数已经执行,如何停止它。

如果你想阻止performSegueWithIdentifier,你可以这样做:

override func shouldPerformSegueWithIdentifier(identifier: String,sender: AnyObject?) -> Bool {
    if ... { // Set the condition if you want it can be perform
        return true
    } else {
        return false
    }
}

只需在第一次执行 segue 时设置一个标志。像这样:

var seguePerformed = false

func updateDistance(distance: CLProximity) {
    UIView.animateWithDuration(0.8) {
        switch distance {
        case .Unknown:
            print("unknown")
        case .Far:
            print("far")
        case .Near:
            print("near")
        case .Immediate:
             print("Immediate")
             if !self.seguePerformed {
                 self.seguePerformed = true
                 self.performSegueWithIdentifier("beaconSegue", sender: self)
             }
        }
    }
}