我正在使用分割视图控制器.对于iPad,当应用程序启动时,我想在主视图控制器的第一项中选择.那我怎么能在Swift中做到这一点?谢谢!
我解决了这个问题.我写这篇文章是为了将来帮助别人.
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 } } }