Custom UITableViewCell not calling prepareForSegue
You need to implement
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:nil];
}
prepareForSegue not being called in uitableviewcontroller
You are using wrong method instead of your method use this below method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
you are missing "sender" that's why your method not being called.
Segues can be triggered from multiple sources, you can use the information in the segue and sender parameters to disambiguate between different logical paths in your app Check this
PrepareForSegue from a UIButton in a custom prototype cell
You could get the index path of the cell like so
let indexPath : NSIndexPath
if let button = sender as? UIButton {
let cell = button.superview?.superview as! UITableViewCell
indexPath = self.tableView.indexPathForCell(cell)
}
You'll also need to change your makeSegue
like this:
func makeSegue(button:UIButton) {
self.performSegueWithIdentifier("toCoriViewController", sender: button)
}
and in your cellForRowAtIndexPath
just change the line where you set the action to cell.button.addTarget(self, action: "makeSegue:", forControlEvents: UIControlEvents.TouchUpInside)
.
Alternatively, you could create a squadra
property inside your custom cell class to hold the arrayCori
value of that cell, so you'd have some code that looks like this:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
let squadra = DataManager.sharedInstance.arrayCori[indexPath.row]
cell.squadra = squadra #add this line
cell.backgroundColor = UIColor.clearColor()
if (indexPath.row % 2 == 0)
{
cell.backgroundColor = UIColor.greenColor()
}
else
{
cell.backgroundColor = UIColor.blueColor()
}
//Here I added target to the button in the cell, and below in the class I implemented the fun makeSegue()
cell.button.addTarget(self, action: "makeSegue", forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "toCoriViewController"
{
let controller = segue.destinationViewController as! CoriViewController
if let button = sender as? UIButton {
let cell = button.superview?.superview as! CustomCell
controller.coriSquadra = cell.squadra
}
}
}
prepareForSegue not getting called when registering a custom cell
The problem is caused by registering the class of the cell in viewDidLoad,
[self.tableView registerClass:[MMTableViewCell class] forCellReuseIdentifier:@"Cell"];
You setup the segue from a cell in the storyboard, but by registering your class, the table view gets its cell from the class definition, not from the one in the storyboard that has the segue attached to it. To fix the problem, just delete that line.
The documentation for this is somewhat incomplete. You should only register the class if the cell is made completely in code. The fact that you're using a custom cell, doesn't change this fact -- if you have a cell in the storyboard, and you set it to a custom class, you shouldn't register anything.
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(...)
Related Topics
App Could Not Authenticate with Facebook and Firebase After Conversion to Swift 3 Syntax
iOS - Combine/Concatenate Multiple Audio Files
Xcode 13 - "Button" Title Not Disappearing
Using Shader Modifiers to Animate Texture in Scenekit Leads to Jittery Textures Over Time
How to Go to Specific Native View Controller from React-Native Code
Svg Viewbox Height Issue on iOS Safari
iPhone /iOS: Presenting HTML 5 Keyboard for Postal Codes
How to Detect If The HTML5 Autoplay Attribute Is Supported
Allow Zooming Within Iframe But Not on Page in iOS
Apn Custom Notification Sound Issue
Why Does 'Position:Fixed' Not Work When Viewed in an 'Iframe' Using an iPhone or iOS Device
iOS 8 and Xcode 6 Simulator Display Out of Alignment
How to Change Select Box Background Without Losing The Right Arrow on Mobile Safari
How to Install Self-Signed Certificates in iOS 11
Cocos2D Sprite Repeat Animation Forever
How to Add Pagination in UItableview.
Cannot Pass Immutable Value as Inout Argument: Literals Are Not Mutable, Why