Search code examples
iosswiftsegueuistoryboarduistoryboardsegue

Is it possible to have 2 segues attached to the UITableViewCell that point at two different UIViewControllers?


Currently I have a UITableViewCell and I attached a segue of type show there - when user clicks the cell this method gets invoked:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

     if (segue.identifier == "fullEventSegue"){


        fullEventDetails = segue.destinationViewController as? FullEvent


    }
}

and then user gets redirected from this cell to the FullEvent class (and view). But now I want to check if that's a user of type A, and if yes then redirect him as usual, but if not - then redirect him to the PartialEvent, something like:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
   if (user == "typeA")
    {
     if (segue.identifier == "fullEventSegue"){


        fullEventDetails = segue.destinationViewController as? FullEvent


    }
  }else{

if (segue.identifier == "partialEventSegue"){


        partialEventDetails = segue.destinationViewController as? PartialEvent


    }
  }
}

I tried to attach two segues on storyboard but when I attach a second one - the first one disappears and for me it looks like I can attach only one segue. Is there any way of fixing it and using both of them at the same time?


Solution

  • Attach the segues to the view controller instead of the cell. Then, implement your test logic inside your didSelectRowAtIndexPath method.

    Depending on which user type, call performSegueWithIdentifier and pick the matching identifier.