I have a UITableView listing multiple types of objects, and I’d like to segue to a different view depending on which type of object the user selects.
Is it possible to do this by using multiple segues, and, if so, how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Of course ! Define all your segues on your storyboard, by ctrl-dragging from the tableViewController (not a row, the tableViewController itself) to the next view. Give them IDs, so you know which one to call. When all your segues are defined visually, go to the code. In your tableView’s delegate, in
didSelectRowAtIndexPath, simply call the segue you want, by checkingindexPath.row:That way, the segue with the ID “Segue0” will be fired when the user selects the first row, and so on.
You can also add the line :
[tableView deselectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] animated:YES];at the beginning ofdidSelectRowAtIndexPathso the row does not remain selected after the user touched it !Edit : This works for both static and dynamic cells ! Be careful to ctrl-drag your segue from the tableViewController, not a cell !