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.
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. 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
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:
performSegueWithIdentifier
and when the asynch function has completed you decide what you do looking at the resultfalse
to cancel the current segue