Add xib UIView to the storyboard view controller without using code

I am trying to reuse a specific view. Say it's a five-button voting system. Since it appears in different scenes / screen, I just wanted to have one view and reuse it where necessary. Therefore, I create a view in the xib file with the name MyStarSystem.xib. Now I want to just leave my eye on the storyboard view manager through the storyboard , not the code.

If all goes well, I know that I have to do this by simply dragging and dropping the UIView into the view controller, and then set the class as UIVotingView. But where can I say UIVotingViewfor drawing xib content? And, of course, the buttons should be interactive, so I want to have IBOutlets and IBActions. Therefore, I thought to use -(void)drawRect:(CGRec)rect, but it does not make any sense as a solution. Does anyone know how I can create this view once and use it in everything - dropping it into a storyboard?

+4
source share
2 answers

, , , IBActions . - , , , , , . , , , . , ( .h, .m). - , .

+1

, , a xib Storyboard, , :

1) , :

- .h .xib :

    #import <UIKit/UIKit.h>
    //here you have to import your voting view so:
    #import "VotingView.h"

    @interface ViewController : UIViewController {

}

@end

- xib view :

    #import <UIKit/UIKit.h>
    #import "VotingView.h"

    //change you UIViewController in to your VotingView like this 

    @interface ViewController : VotingView {

    }

@end
  • ok ViewController.m VotingView, , VotingView - (void)voting {} ViewController.m ViewDidLoad [self voting];

, XIB :

ViewController , IBAction xib:

- (IBAction)callXib:(id)sender{

ViewController *viewController=[[ViewController alloc]initWithNibName:@"MyStarSystem" bundle:nil];

[self presentViewController:viewController animated:YES completion:nil]; 

}

, xib , :

- (IBAction)backTo:(id)sender{

[self dismissViewControllerAnimated:YES completion:nil];

}

, !

-2

All Articles