Function inside prepareForSegue will not execute
I responded to your last post as well, but You are sending an array of channels to
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if let channel = sender as? Channel {
print("executed")
let chatVc = segue.destination as! channelMultiplayerViewController
chatVc.channel = channel
chatVc.channelRef = channelRef.child(channel.id)
}
}
So the block - if let channel = sender as? Channel - will not work.
Change the cell selection code to:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == Section.currentChannelsSection.rawValue {
if searchController.isActive && searchController.searchBar.text != "" {
let channel = filteredChannels[indexPath.row]
self.performSegue(withIdentifier: "ShowChannel", sender: channel)
}
else
{
let channel = channels[indexPath.row]
self.performSegue(withIdentifier: "ShowChannel", sender: channel)
}
}
}
prepareForSegue is not getting called when I click on a button without using performSegueWithIdentifier
Well, as it turns out, my view controller where button calls the modal view did not have the right class where prepareForSegue is implemented. It was the default UIViewController instead of my custom class.
The way I figured it out was by putting a break point in viewDidLoad and even that was not breaking and thus I suspected that in the storyboard I did not have the right class associated with the view where the button is implemented.
Variable is empty inside of prepareforsegue function
I have the tableview cell connected to the secondviewcontroller through a segue called "showStoreDetailsSegue".
That’s the problem. You are performing the segue twice, and the first time is before didSelect
is called.
One solution: Connect the segue from the view controller, not the cell.
Alternatively (and better), delete your didSelect
implementation itself. You don’t really need selectedStores
. Just use prepare
to find out what the selection is, and go from there.
swift 3 prepare(for segue: ) function broken?
Your method isn't getting called at all because you have the wrong signature. It was changed in Xcode 8 beta 6 to:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
Note that the type of sender
is Any?
instead of AnyObject?
. You should have had an error after upgrading Xcode which told you your method wasn't overriding any method from its superclass which should have clued you in before you deleted the override
.
Swift Prepare(for: segue) not called
You are calling performSegue
on self.navigationController
, so it's the navigationController.prepareForSegue
that will be called, not the one in your VC. You should reconnect the segue to your VC in the storyboard, give it the identifier, and call:
self.performSegue(...)
Prepare for Segue function not passing data correctly
You sender is a new instance of UIButton
which doesn't have any of the information you need. Instead pass the button calling the selector.
@objc func displayStatDetail(_ sender: StatisticButton) {
self.performSegue(withIdentifier: "StatDetailSegue", sender: sender)
}
You would need to change the target selector like this in the loop.
statisticButton.addTarget(self, action: #selector(displayStatDetail(_:)), for: .touchUpInside)
PrepareforSegue function is never running, variables in additional view controller are blank
Your prepareForSegue is never called because you use presentViewController() function. It's simply push an other view controller.
A segue is a link between two view controllers in Storyboard, so you can add a segue in Storyboard between view controllers, set an ID to the segue and use performSegueWithIdentifier("mySegueID", sender: nil) instead.
Related Topics
How to Load Lcr Image in Tvos Apps
How to Hide The Top Bar (With Buttons) Usin Swift and Macos
Given a Swift 'Any' Type How to Determine If It's an 'Optional'
How to Have a Searchbar Which Shows Suggestions with Different UItableview
How to Assign Elements of a Dictionary to JSON Object in Vapor 3
Swiftui Navigationview Starting Inside Itself
How to Drag a Working Slider Using Swiftui
How to Run Terminal Command in Swift from Any Directory
Uialertview or UIalertcontroller to Display Only Once in Swift
How Make Polygon Without Intersection in Swift
Swift: How to Get Image Name from Assets
Verifying The Purchase (Receipt) of Another Application (Mac App Store)
Firebase Cloud Firestore - Initializing a Collection
How to Get Window Reference (Cgwindow, Nswindow or Windowref) from Cgwindowid in Swift
How to Bend a Rectangle in Sprite Kit
Firebase Remove Snapshot Children Swift
How to Use Mtlblitcommandencoder for Copying Interlaced Video Fields into a Mtlbuffer