APK APPS APK APPS - 1 year ago 109
iOS Question

segue getting twise call in swift

I have two view Controller one is ScheduleController and other is EditShiftController. In ScheduleController I have a table view name is scheduleTable. In the scheduleTable I have a cell with identifier ScheduleWithData. In this cell i have two different button Button EDIT and Button DELETE. i have directly connected button EDIT with EditShiftController with segue identifier editShiftSegue.

The Code of TableViewCell.swift

var editShiftClick: (() -> Void)? = nil
@IBAction func editShiftBtn(sender: AnyObject) {
if let onButtonTapped = self.editShiftClick {

The Code of ScheduleController.swift

myCell!.editShiftClick = {
self.performSegueWithIdentifier("editShiftSegue", sender: dataTemp[indexPath.row].id)

The function for prepareSegue in ScheduleController.swift

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "editShiftSegue") {
if (sender != nil) {
let svc = segue.destinationViewController as! EditShiftViewController;
svc.label = String(sender)

Snip Shot of Segue
enter image description here

When I click on EDIT button then EditShiftController getting twice call I don't know why
please, can any one help me here Thank you in Advance

Answer Source
 myCell!.editShiftClick = {
        //self.performSegueWithIdentifier("editShiftSegue", sender: dataTemp[indexPath.row].id)

Comment self.performSegueWithIdentifier("editShiftSegue", sender: dataTemp[indexPath.row].id) this line because if you have connected edit button directly with segue then no need to performsegue programatically also!!


  myCell!.editShiftClick = {
        self.performSegueWithIdentifier("editShiftSegue", sender: self)

don't comment that line and delete that segue which is given from edit button. give segue from viewcontroller to viewcontroller and give identifier editShiftSegue and then perform segue as above code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download