I want to know that how can I set an default Detail View Controller when nothing is selected in master view controller in iPad in Swift.
For example, if the app just load inside and user didn't select anything, the detail view controller will be ViewControllerDefault
, if user select any of the rows in master view controller, the detail view controller will be ViewControllerResult
. So how can I do that in Swift? Thanks!
Over a long time has been passed, I hope it helps someone.
func viewDidLoad() {
//..
let initialIndexPath = NSIndexPath(forRow: 0, inSection: 0)
self.tableView.selectRowAtIndexPath(initialIndexPath, animated: true, scrollPosition:UITableViewScrollPosition.None)
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
self.performSegueWithIdentifier("ShowDetail", sender: initialIndexPath)
}
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowDetail" {
if sender!.isKindOfClass(UITableViewCell) {
if let indexPath = self.tableView.indexPathForCell(sender as! UITableViewCell) {
// Get row from selected row in tableview
}
} else if sender!.isKindOfClass(NSIndexPath) {
let tableCell = self.tableView.cellForRowAtIndexPath(sender as! NSIndexPath)
let indexPath = self.tableView.indexPathForCell(tableCell!)
// Get row from sender, which is an NSIndexPath
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With