Reputation: 3829
I'm setting a delegate on a segue, but I need it to be set to the existing SfnViewController
rather than what appears to be happening here which is creating a new one.
How can I access the existing SfnViewController
to pass it through?
class ViewerListController {
func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
editViewer = fetchedResultController.objectAtIndexPath(indexPath) as? Viewer
performSegueWithIdentifier("editViewer", sender: indexPath)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "editViewer" {
let editViewerViewController = segue.destinationViewController.topViewController as! EditViewerViewController
editViewerViewController.viewer = editViewer
//Need this as the existing SfnViewController
editViewerViewController.delegate = SfnViewController()
}
}
}
Upvotes: 0
Views: 47
Reputation: 131471
We can't really help you because you haven't provided enough information. You say you have an existing SfnViewController.
If your only have one shared SfnViewController for you entire object you should consider following the singleton design pattern and making your SfnViewController a singleton. Then you'd use a class method of the SfnViewController class to get a reference to the singleton.
Upvotes: 1
Reputation: 3599
If you mean using some specific controller which you can determine in the tableView:accessoryButtonTappedForRowWithIndexPath: method, then you should send it in the "sender" property when calling performSegueWithIdentifier like this:
class ViewerListController {
func tableView(tableView: UITableView, accessoryButtonTappedForRowWithIndexPath indexPath: NSIndexPath) {
editViewer = fetchedResultController.objectAtIndexPath(indexPath) as? Viewer
performSegueWithIdentifier("editViewer", sender: editViewer)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "editViewer" {
let editViewerViewController = segue.destinationViewController.topViewController as! EditViewerViewController
editViewerViewController.viewer = editViewer
let editViewer = sender as! EditViewerViewController
editViewerViewController.delegate = editViewer.delegate
}
}
}
Upvotes: 0