【问题标题】:iOS - Loading a xibiOS - 加载 xib
【发布时间】:2014-11-26 18:52:30
【问题描述】:

任何人都知道为什么当我使用这段代码时,它不会将视图缩放到屏幕大小。看起来它按原样加载 xib 文件,并且不适合设备的宽度。

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ReceiptView" owner:self options:NULL];
        self = (ReciptView *)[nib objectAtIndex:0];

    }
    return self;
}

这是控制器中的实现:

-(void) bookNowAction
{
    ReciptView *v = [[ReciptView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:v];
}

【问题讨论】:

    标签: ios uiview xib


    【解决方案1】:

    在调用 super initWithFrame 之后,您正在 if 块中重新分配 self。您实际上是在消除该调用的影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多