I have an application without a storyboard, all the user interface creation is done in code, and I got a splitView that I would make it suitable for use on the iPhone, because since the application was first developed only for the iPad, so when you select the line in the list in the "Master" view does nothing on the iPhone, but works fine on the iPad.
So my question is, can I create and execute a segue, which allows me to show the Detail View using the didSelectRowAtIndexPath method?
Here is what I have done so far:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let segue = UIStoryboardSegue(identifier: "test", source: self, destination: detailViewController!) performSegueWithIdentifier("test", sender: self) }
but when I started and selected the line, the application worked, saying that it needed a execution handler, so I added the following:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let segue = UIStoryboardSegue(identifier: "test", source: self, destination: detailViewController!, performHandler: { () -> Void in let object = self.fetchedResultsController.objectAtIndexPath(indexPath) let controller = self.detailViewController! controller.detailItem = object controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem() controller.navigationItem.leftItemsSupplementBackButton = true }) performSegueWithIdentifier("test", sender: self) }
and now, when you select the xcode string, it says that there is no segment with that identifier "test".
I also tried calling it segue.perform() and adding the contents of the performHandler to the prepareForSegueMethod method:
if segue.identifier == "test" { if let indexPath = self.tableView.indexPathForSelectedRow { let object = self.fetchedResultsController.objectAtIndexPath(indexPath) let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController controller.detailItem = object controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem() controller.navigationItem.leftItemsSupplementBackButton = true } }
and it doesnโt do anything, it doesnโt crash, just select the selected line i
Can you guys help me?
EDIT: As Oleg Gordyuchuk said, it's impossible to do what I want to do without a storyboard, so thanks for the help :)