0

I have a base view controller BaseUIViewController which is extended from UIViewController. I have two UIButtons at the bottom of this ViewController. Basically I want these two buttons on every UIViewController at the same place through out my app. When I extend BaseUIViewController, I don't see them in the children view controllers. I have given IBOutlets to the buttons too! I am new to programming. Please help. Isn't this way inheritance work?

3 Answers3

1

You can create a UIViewControllerContainment. This Stackoverflow's post explains it in detail how you can create it and make it work. Similalry, also have a look at this Stackoverflow's post. Here it is done using childViewControllers.

Community
  • 1
  • 1
Munahil
  • 2,381
  • 1
  • 14
  • 24
0

Make sure you put these button properties in @interface instead of @implement, only properties in @interface can see in subclasses. Here is example:

@interface BaseUIViewController
    @property (nonatomic, weak) IBOutlet UIButton *button1;
    @property (nonatomic, weak) IBOutlet UIButton *button2;
@end
ninjapro
  • 105
  • 5
0

Both the ways which MUNAHIL answered above, are the best ones I believe. In case you want to achieve this in a more basic way, you can do as below.

  • Add the two UIButtons in the BaseUIViewController (either programmatically in viewDidLoad or in storyboard). In case you need, you may like to add a UIToolBar first and then the buttons on top of it.
  • Make other view controllers a subclass of BaseUIViewController.

    @interface SomeViewController: BaseUIViewController
    
  • Now, all your view controllers will have the two buttons by default.

Rashmi Ranjan mallick
  • 6,390
  • 8
  • 42
  • 59