简体   繁体   English

如何从ios 9中的xib文件添加子视图?

[英]How to add subview from xib file in ios 9?

I have an old project that facing a bug since the user updating their os to ios 9.0. 我有一个老项目,因为用户将其操作系统更新为ios 9.0,因此面临错误。 The thing is my view is loaded, all button and function working fine but the ui is just blank. 关键是我的视图已加载,所有按钮和功能都正常运行,但是ui只是空白。

here is screenshot of my app running on ios 8.1 这是我的在iOS 8.1上运行的应用的屏幕截图 在此处输入图片说明

and here is my app running on ios 9.1 这是我在iOS 9.1上运行的应用

在此处输入图片说明

And here is my code: 这是我的代码:

my viewcontroller.h file: 我的viewcontroller.h文件:

@property (strong, nonatomic) IBOutlet UIScrollView *theScrollView;
@property (weak, nonatomic) IBOutlet UIView *mainToolbar2;

my viewcontroller.m: 我的viewcontroller.m:

CGRect scrollViewRect = CGRectInset(viewRect, -scrollViewOutset, 0.0f);
self.theScrollView = [[UIScrollView alloc] initWithFrame:scrollViewRect]; // All
self.theScrollView.autoresizesSubviews = NO;
self.theScrollView.contentMode = UIViewContentModeRedraw;
self.theScrollView.showsHorizontalScrollIndicator = NO;
self.theScrollView.showsVerticalScrollIndicator = NO;
self.theScrollView.scrollsToTop = NO;
self.theScrollView.delaysContentTouches = NO;
self.theScrollView.pagingEnabled = YES;
self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.theScrollView.backgroundColor = [UIColor redColor];
self.theScrollView.delegate = self;

if (_isArabic) {
    self.theScrollView.transform=CGAffineTransformMakeRotation(M_PI * (180) / 180.0);
}

[self.mainView addSubview:self.theScrollView];

CGRect toolbarRect = viewRect;
toolbarRect.size.height = TOOLBAR_HEIGHT;
self.mainToolbar = [[ReaderMainToolbar alloc] initWithFrame:toolbarRect document:document]; // ReaderMainToolbar
self.mainToolbar.delegate = self; // ReaderMainToolbarDelegate
[self.mainView addSubview:self.mainToolbar];

if (fakeStatusBar != nil) [self.mainView addSubview:fakeStatusBar]; // Add status bar background view

for (UIView *subView in self.mainToolbar.subviews)
{
    [subView removeFromSuperview];
}

[self.mainToolbar addSubview:self.mainToolbar2];

I think there are some change on ios 9 for adding subview from xib file that I didn't know. 我认为ios 9上有一些更改,用于从xib文件添加子视图,我不知道。 How can I fix this problem so that app can run on ios 9 too? 如何解决此问题,使应用程序也可以在ios 9上运行?

I don't think there is any difference in adding subview. 我认为添加子视图没有任何区别。 You may try something like... 您可以尝试类似...

  • Comment the line self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 注释该行self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  • Change weak to strong in line @property (weak, nonatomic) IBOutlet UIView *mainToolbar2; @property (weak, nonatomic) IBOutlet UIView *mainToolbar2;弱变为强@property (weak, nonatomic) IBOutlet UIView *mainToolbar2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM