[英]Is it possible to delay and/or cancel a Show Detail segue for UISplitViewController?
I would like to use a UISplitViewController
to show a list of connectable devices in the master view, and to show information retrieved from a selected device in the detail view. 我想使用UISplitViewController
在主视图中显示可连接设备的列表,并在详细视图中显示从选定设备检索到的信息。
To do that, when the user taps on a device, I need to attempt to connect to that device. 为此,当用户点击设备时,我需要尝试连接到该设备。 If unsuccessful, there'd be nothing to show and I would display an error message. 如果不成功,将没有任何显示,我将显示一条错误消息。 If successful, I'd read data from the device and display that in the detail view. 如果成功,我将从设备中读取数据并将其显示在详细视图中。
The Show Detail segue from the UISplitViewController
seems to automatically fire immediately after an entry in the master view is tapped. 轻按了主视图中的条目后, UISplitViewController
“显示详细信息” UISplitViewController
似乎会立即自动触发。 Can I intercept this somehow to add the necessary logic for connection/read? 我可以以某种方式拦截此操作以添加用于连接/读取的必要逻辑吗? If not, what is an alternative method for me to do this? 如果没有,我有什么其他替代方法?
In your ViewController you can override shouldPerformSegueWithIdentifier
在您的ViewController中,您可以覆盖shouldPerformSegueWithIdentifier
class Foo: UIViewController {
func doAsynchStuff(completion: (canProceed:Bool)->()) {
// ...
}
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
if everythingOK {
return true
} else {
// do your stuff
doAsynchStuff({ (canProceed) -> () in
if canProceed {
self.performSegueWithIdentifier(identifier, sender: sender)
} else {
// present error message
}
})
return false
}
}
}
If you return true
the segue will be execute, otherwise you: 如果返回true
,则将执行segue,否则,您将:
performSegueWithIdentifier
and when the asynch function has completed you decide what you do looking at the result 调用performSegueWithIdentifier
然后在异步函数完成后决定查看结果 false
to cancel the current segue 返回false
取消当前的segue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.