How to select default item in detail view for iPad? (in Split View Controller)
I solved this problem. I am writing to help others in the future.
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
}
}
}