Question

I create View with elements in storyBoard. Now I want to use it. Problem is that I can not drag element from that view to class of this view. Why?

My purpose is to create view in storyboard and then use it like

 MyView *mv= [[MyView alloc]initWithFrame:..];

and then assign it to show to button tap

Was it helpful?

Solution 2

You can create your additional views inside a storyboard if you prefer. The key is to create them in the same ViewController Scene, but outside of the viewController. Create an IBOutlet for the view in your viewController.m by dragging the secondary view to the viewController and then you can access it in the same way you would with any other IBOutlet. If this is a custom view you can set the class in the identity inspector as you would with any other custom class in storyboards.

For a full example, look at Apples KeyboardAccessory sample Code, specifically, look at the AccessoryView

https://developer.apple.com/library/ios/samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html

KeyboardAccessory Storyboard

OTHER TIPS

Check whether your class files and view has the same name.

Class files

Also your class file should be a subclass of UIView.

enter image description here

Then in your Interface builder, click on 'Show the identity inspector' for View.xib and check the Custom Class name.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top