I have a custom MyUITableViewController, that I have a segue when user select one of the rows to another ViewController that shows the details of about the item in that row. (I build using Storyboard, and Segue Identifier, "foobar").

I created another ChildTableViewControler which inherits from MyUITableViewController. Since the items displayed in it is the same, I just have a different set of items, I would like the behavior of the select item to be the same. So i.e. when user select one of the rows, I want it to perform the same segue. So I would assume I don't have to write the segue code again.

However, when I run the app and click one of rows in the ChildTableViewController, it says the segue with identifier "foobar" is not found, and crashes.

So there is no inheritence in segue? I have to write segue code repeatly?

没有正确的解决方案

其他提示

As this question remains open, here goes an answer:

The first important thing to mention is that the segue is not a ViewController property, if you go to the UIViewController class and search for segue, you will find only methods and no property, which already is a sign that it can't be inherited. Then if you check the UIStoryboardSegue interface you will find this:

@property (nullable, nonatomic, copy, readonly) NSString *identifier;
@property (nonatomic, readonly) __kindof UIViewController *sourceViewController;
@property (nonatomic, readonly) __kindof UIViewController *destinationViewController;

In the UIStoryboardSegue documentation you will find:

A UIStoryboardSegue object is responsible for performing the visual transition between two view controllers. In addition, segue objects are used to prepare for the transition from one view controller to another. Segue objects contain information about the view controllers involved in a transition The UIStoryboardSegue class supports the standard visual transitions available in UIKit. You can also subclass to define custom transitions between the view controllers in your storyboard file.

The segue is responsible only for the visual transition between viewControllers and that the segue holds information about the specific viewControllers involved in this transition, also meaning that the segue is specifically about those view controller, as it references to them.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top