1

I have a number of View Controllers that share properties/behavior, so naturally I made them inherit from a common base controller. One thing they all have in common is a footer object (UIImageView), though with a different image. The UIImageView is defined in the base class.

When I add the image view to the controllers in the storyboard and wire them up to the object defined in the base class, it seems to work fine but the image doesn't display unless I write code and manually add the image to the view of the view controller.

If I define UIImageView on each of the concrete classes instead of the base class, everything works fine. So to give a more clear example, say I have:

BaseViewController

  • (IBOutlet) UIImageView;

ChildViewController1 : BaseViewController

ChildViewController2 : BaseViewController

I can add the image to child 1 and 2 in the storyboard and assign it to the image view defined in the base but the image won't show unless I manually code it. But if I do this:

BaseViewController...

ChildViewController1 : BaseViewController

  • (IBOutlet) UIImageView;

ChildViewController2 : BaseViewController

  • (IBOutlet) UIImageView;

If I wire this up in the storyboard the images show without any code written. Also, if I simply add an image to the view controllers without any wiring up, they show fine.

Any ideas?

5
  • in the init methods of your subclasses, are you making sure to call [super initWithNibName:bundle:]? Commented Dec 22, 2013 at 0:24
  • @PatrickGoley initWithNibName:bundle: is not called for storyboards. Instead, initWithCoder: is called. Commented Dec 22, 2013 at 0:25
  • @LeoNatan you are correct my mistake. the point remains though, if you don't call super you won't get the base class's functionality. based on the description, it seems as though he may be calling self = [self initWithCoder:]; Commented Dec 22, 2013 at 0:27
  • @PatrickGoley That would create an endless recursion. Also, he mentioned he was able to add code to make the view appear. If he didn't have code to initialize the superclass, the footer view property would be nil. Commented Dec 22, 2013 at 0:31
  • Calling super initWithCoder didn't work. Commented Dec 22, 2013 at 1:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.