【问题标题】:scrollview add other page xib's viewsscrollview 添加其他页面 xib 的视图
【发布时间】:2013-12-03 02:10:21
【问题描述】:

我有两个 .xib 文件。第一个 xib 名称是 viewcontroller.xib ,它包含使用页面控制的滚动视图。

第二个 xib 名称是 registration.xib ,它包含标签文本字段和提交按钮。

我的问题是我想将registration.xib文件的整个视图添加到viewcontroller.xib文件的滚动视图中。

我该怎么办?????????????

        //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];

在注册中

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

self.view11.translatesAutoresizingMaskIntoConstraints=NO;

}

【问题讨论】:

  • 这里 view11 是 UIView 在 .h 文件中声明。
  • 如果您使用的是 XIB,是否有理由不使用 [[RegistrationViewController alloc] initWithNibName:@"RegistrationViewController" bundle:nil]

标签: iphone uiscrollview ios7 xib


【解决方案1】:

感谢亲爱的回复我,但您的代码不起作用...我的设置方法在此行之后调用

            regiViewController=[[RegistrationViewController alloc]init];

// 再次查看 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

【讨论】:

  • 此代码正在运行,但最后它不会在 viewcontroller.xib 的 uiscrollview 中显示registration.xib。它只是在滚动视图中向您显示紫色。没有别的。
  • heyyyyy 伙计们,上面的代码完全成功....只是 xib 没有正确显示在滚动视图中
【解决方案2】:

我个人会使用

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

而不是从 [setup] 方法加载 XIB,但这只是我。但是,在您当前的代码中,viewcontroller.m 从不调用 setup 方法,因此从不加载 XIB。试试这个:

//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]; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    相关资源
    最近更新 更多