How to “cancel” a UIStoryBoardSegue

前端 未结 9 1870
小蘑菇
小蘑菇 2020-12-23 21:40

Does anyone know how to \"stop\" a segue transition conditionally:

My table view cells represent products which can be viewed in a drill-down \"detail\" view... or

9条回答
  •  余生分开走
    2020-12-23 21:50

    I am using an much easier and tidy approach.

    Storyboard

    1. Create two identical cell with different identifiers. Eg: "cellWithSegue" and "cellWithoutSegue".
    2. Connect the first cell ("cellWithSegue") with the segue you want to display.
    3. Do not connect the second cell with any segue.

    Table View

    1. On cellForRowAtIndexPath, implement a logic to determine if the cell should be linked a segue or not.
    2. For cells that should be linked with the segue use the "cellWithSegue" identifier, for the rest the "cellWithoutSegue".

    This way looks a lot easier to implement and also does not alter the way segues are supposed to work.

提交回复
热议问题