André Fratelli
André Fratelli

Reputation: 6068

Custom class does not show in attributes inspector

When using storyboard, I usually set the Custom Class in Identity Inspector to be the class of my views and view controllers. This time, I created a base class that inherits from UIPageViewController (PageViewController) and then two other classes (ProfilePageViewController, and ContextPageViewController) that in turn inherit from PageViewController.

The idea is for PageViewController to extend the functionality of UIPageViewController by providing mechanisms that will be common to both ProfilePageViewController and ContextPageViewController. So far so good.

Then I drag a couple of view controllers to the interface builder and set the classes I wrote before as Custom Class (again, that's ProfilePageViewController, and ContextPageViewController).

If I had used a UIPageViewController from scratch instead, the Properties Inspector would look something like this:

enter image description here

But it doesn't.

One other thing. I know that if I drag a UIPageViewController and then change the custom class, this will show properly. However, both ProfilePageViewController and ContextPageViewController are inside Container Views, which pretty much means that Xcode generated them automatically. That is:

  1. I create a parent view controller
  2. Drag two container views into it
  3. Xcode generates two UIViewControllers automatically
  4. I want these two view controllers to be of a custom class which is a subtype of UIPageViewController.

What the attributes inspector shows, instead, is just the properties for view controllers:

enter image description here

How can I make these properties show?

Upvotes: 0

Views: 1074

Answers (1)

André Fratelli
André Fratelli

Reputation: 6068

I spent quite some time and effort trying to do this, and it turns out that it's quite simple.

  1. Drag a Page View Controller onto the canvas;
  2. Change it's custom class property;
  3. Control + drag from the container to the new controller;
  4. Click "embed".

Xcode will automatically replace the controller that it generated automatically. You can delete that.

Upvotes: 4

Related Questions