Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 131 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Perform a segue programmatically

#1
Hi I'm trying to perform a segue programmatically without the Storyboard. Currently I have this as my code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "popOutNoteExpanded" {
let vc = segue.destination as! ExpandedCellViewController
let cell = sender as! AnnotatedPhotoCell
sourceCell = cell
vc.picture = cell.imageView.image
print("button pressed")
}
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "popOutNoteExpanded", sender: indexPath)
}

When I click on the collection view cell it's saying that:

> has no segue with identifier 'popOutNoteExpanded'.

Not sure how to perform my custom animated transition.
Reply

#2
In my case I was presenting a TableViewController, without a segue defined, and found it was necessary to instantiate from the storyboard otherwise `tableViewCells` couldn't be dequeued in `cellForRowAt`.

let vc = (storyboard.instantiateViewController(withIdentifier: "YourTableViewController") as? YourTableViewController)!
self.navigationController!.pushViewController( vc, animated: true)
Reply

#3
Additional to the correct answer, please be aware that if you are in a navigation stack (say, you are in a Settings page and want to segue to an MyAccountVC) you should use:


let vc = MyAccountVC()
self.navigationController?.pushViewController(vc, animated: true)

If the navigated VC appears with a transparent background during the transition, just set the `backgoundColor` of it to `.white`.
Reply

#4
To trigger a segue programmatically, you have to follow steps:
1. Set it up in Storyboard by **dragging your desired segue between two view controllers** and **set its identifier** (for example, in your case is "popOutNoteExpanded") in Attributes Inspector section.
2. Call it programmatically

performSegue(withIdentifier: "popOutNoteExpanded", sender: cell)

Please check if you set its identifier correctly or not.


Besides, in your above code, you put **an incorrect sender**.
In your *prepare()* method, you use the sender as a *UITableViewCell*, but you call *performSegue()* with sender as a *IndexPath*.
You need a cell by calling:

let cell = tableView.cellForRow(at: indexPath)


And then you can perform a segue:

performSegue(withIdentifier: "popOutNoteExpanded", sender: cell)
Reply

#5
Segues are components of storyboard. If you don't have a storyboard, you can't perform segues. But you can use present view controller like this:

let vc = ViewController() //your view controller
self.present(vc, animated: true, completion: nil)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through