0

i have two .xib file. First xib name is viewcontroller.xib , it contain scrollview using page control.

second xib name is registration.xib , it contain labels textfield and submit button .

my question is that iwant to add the whole views of registration.xib file into the scrollview of viewcontroller.xib file .

what can i do ???????????

        //In viewdidload of viewcontroller.m

        regiViewController=[[RegistrationViewController alloc]init];

        regiViewController.view11.translatesAutoresizingMaskIntoConstraints=NO;


        UIView *containerView=[[UIView alloc]initWithFrame:CGRectMake(self.scrollView.frame.size.width * i, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
        containerView.backgroundColor = [UIColor purpleColor];

        [containerView addSubview:regiViewController.view11];


        [scrollView addSubview:containerView];

In registration.m

       - (void)setup {
[[NSBundle mainBundle] loadNibNamed:@"RegistrationViewController" owner:self options:nil];
[view11 addSubview:self.view];

self.view11.translatesAutoresizingMaskIntoConstraints=NO;

}

rmaddy
  • 314,917
  • 42
  • 532
  • 579
MAC113
  • 1,444
  • 12
  • 19

2 Answers2

0

Personally I would use

[[RegistrationViewController alloc] initWithNibName:@"RegistrationViewController" bundle:nil];

rather than loading the XIB from the [setup] method but that's just me. However, in your current code viewcontroller.m never calls the setup method, so the XIB is never loaded. Try this:

//In viewdidload of viewcontroller.m

regiViewController=[[RegistrationViewController alloc]init];

[regiViewController setup];

UIView *containerView=[[UIView alloc] initWithFrame:CGRectMake(self.scrollView.frame.size.width * i, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
containerView.backgroundColor = [UIColor purpleColor];

[containerView addSubview:regiViewController.view11];


[scrollView addSubview:containerView]; 
Uptown Apps
  • 707
  • 1
  • 5
  • 11
0

Thank you dear for reply me but your code not working ...My setup method is called after this line

            regiViewController=[[RegistrationViewController alloc]init];

// see Again viewcontroller.m

              regiViewController=[[RegistrationViewController alloc]init];

    regiViewController.view11.translatesAutoresizingMaskIntoConstraints=NO;


    UIView *containerView=[[UIView alloc]initWithFrame:CGRectMake(self.scrollView.frame.size.width * i, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
    containerView.backgroundColor = [UIColor purpleColor];

    [containerView addSubview:regiViewController.view11];


    [scrollView addSubview:containerView];

//registrationviewcontroller.m

      #import "RegistrationViewController.h"

     @interface RegistrationViewController ()

     @end

      @implementation RegistrationViewController


    @synthesize view11;

  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
   {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     if (self) {
                 // Custom initialization
                 [self setup];
               }
     return self;
   }


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.


}

 - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

- (void)setup {
[[NSBundle mainBundle] loadNibNamed:@"RegistrationViewController" owner:self         options:nil];
[view11 addSubview:self.view];

self.view11.translatesAutoresizingMaskIntoConstraints=NO;
}

  @end
MAC113
  • 1,444
  • 12
  • 19
  • this code is working but at the end it not display the registration.xib in uiscrollview of viewcontroller.xib. It just show you the purple color in scrollview only .nothing else. – MAC113 Nov 20 '13 at 05:50
  • heyyyyy guys this above code is working fully successfully .... just xib not properly display in scrollview – MAC113 Nov 20 '13 at 06:19