简体   繁体   中英

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. The thing is my view is loaded, all button and function working fine but the ui is just blank.

here is screenshot of my app running on ios 8.1 在此处输入图片说明

and here is my app running on ios 9.1

在此处输入图片说明

And here is my code:

my viewcontroller.h file:

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

my 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. How can I fix this problem so that app can run on ios 9 too?

I don't think there is any difference in adding subview. You may try something like...

  • Comment the line self.theScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
  • Change weak to strong in line @property (weak, nonatomic) IBOutlet UIView *mainToolbar2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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