Multiple segues from table view controller

后端 未结 1 1278
耶瑟儿~
耶瑟儿~ 2020-12-30 15:36

I have a small app that uses multiple section layouts for the initial table view. One section displays the most recent trends from Twitter and the other section displays the

相关标签:
1条回答
  • 2020-12-30 16:21

    There's not quite enough information in your question to be sure, but this sounds like an issue with what I'd call automatic versus manual segues and the restrictions on each.

    An automatic segue is created in IB by dragging from a (prototype) table cell or other control. The nice thing about it is that it's, well, automatic -- tapping the control performs the segue, and all you need to do in your code is implement prepareForSegue:sender: so that the destination view controller gets the right data. The downside is that any given control (including prototype table cells) can only have one outgoing segue (otherwise, the storyboard wouldn't know which to automatically perform).

    A manual segue is created in IB by dragging from the source view controller. The upside to this is that a view controller can have multiple outgoing segues. On the other hand, they aren't associated with a tappable control, so you have to implement logic that determines which to perform when (and calls performSegueWithIdentifier: to make it happen).

    Given those tradeoffs, there are two possible solutions to your problem:

    1. Use multiple prototype table cells -- then each can have its own outgoing automatic segue. You'll need to change your table view controller's tableView:cellForRowAtIndexPath: to check the index path's section number and choose the appropriate identifier for dequeueReusableCellWithIdentifier:, but this might make things more convenient or efficient if your trend and story cells have different content anyway.

    2. Use manual segues. Then your table view controller can implement tableView:didSelectRowAtIndexPath: to call performSegueWithIdentifier: with the appropriate identifier chosen based on the index path's section.

    Either way, your prepareForSegue:sender: implementation looks fine.

    0 讨论(0)
提交回复
热议问题