So, I want to create a reusable widget as a xib and subview that can appear on a set amount of specific screens. This widget will have three buttons, each with an Action.
I want to be able to handle these actions on multiple viewcontrollers.
So say ViewControllerA, ViewControllerD, and ViewControllerF can handle the three button events, each in their own way.
I’ve created the nib file. How do I import it into the specific viewcontrollers, and then how do I wire up those events?
EDIT: I know that I could potentially get outlets set up via a viewcontroller, but Apple states that UIViewController is for full-screen views only, and my widget is only taking up a small portion of the screen.
You have done correctly. And one thing is, In
iOSit’s not widget.It’s aUIView.(Sorry there may be any typo in my code.I have written myself in StackOverflow)
Follow Below Steps to finish it..
1) After you have created the
xibfor the view, then you need to have aUIViewsubclass files.. For example yourxibname likes thisCustomView.xibmeans then create a files like thisCustomView.mand CustomView.h2) In your
CustomView.xib, You need to set thefileOwneras yourCustomView.h.3) In your
CustomView.mfile, there will be a method likeinitWithFrame:In that method you need to load your xib file like this4) Almost over. In any of your view controller, you can use this xib like
That’s it.. Go on..