How would I use polymorphism to allow a method to accept multiple classes, but with IBOutlets?

前提是你 提交于 2019-12-04 21:50:42

You can connect outlet of label to different viewControllers with your SuperClass from story board if your different viewControlelrs in storyboard reperset by Subclasses(derived from SuperClass) names in storyboard.

1)Just define

 class SuperClass{
     @IBOutlet weak var label: UILabel! = nil

 }

SubClass1 repersent view controller1 in storyboard derived from SuperClass SubClass2 repersent another view controller2 in storyboard derived from SuperClass

2)Than Go to Assistant Editor and open SuperClass one side and other side view controller1 and connect outlet from SuperClass to label in storyBoard in view controller1.Drag from SuperClass label to storyBoard in view controller1

3)Now again open SuperClass one side and other side view controller2 and connect outlet from SuperClass to label in storyBoard in view controller2.Drag from SuperClass label to storyBoard in view controller2

If you click on SuperClass outlet than you will see two labels conneted to different viewControllers

Declare the IBOutlet in a superclass, AnimalView. Then in Interface Builder, once you have set the custom UIView's class in the Identity inspector to be DogView, go to the Connections Inspector and your nameLabel will be there.

@interface Parent : UIView

@property (nonatomic,weak) IBOutlet UILabel *nameLabel;

@end

@interface Child : Parent

@end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!