Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWindow addSubview is not working in ios 9

following code working fine in ios 8 ,But in ios 9 i am getting white page with no content.

MRForceUpdateView * mForceUpdateView = [[[NSBundle mainBundle] loadNibNamed:@"MRForceUpdateView" owner:self options:nil] objectAtIndex:0];

mForceUpdateView.frame = self.view.frame;

UIWindow * window = [[[UIApplication sharedApplication] delegate] window];

[window addSubview:mForceUpdateView];

please suggest a method to add a custom view on app level .

thanks in advance .

like image 984
Shaik Riyaz Avatar asked Mar 14 '23 15:03

Shaik Riyaz


2 Answers

Unchecking "Use Size Classes" option and then coming back and re-checking it again fixes this issue.

  • In the project navigator, select a storyboard or xib file.
  • The file’s contents open in Interface Builder.
  • Choose View > Utilities > Show File Inspector.
  • In the Interface Builder Document section, un-tick the "Use Size Classes" checkbox.
  • Leave the menu. Come back and tick the "Use Size Classes" checkbox again.
like image 150
Dibin77 Avatar answered Mar 28 '23 09:03

Dibin77


The solution with the size classes is weird to me, because I do not experience any issues for now by adding a subview into the window on iOS 9.

Also i want to point that when the rootViewController is set - all existing views in the window's hierarchy are removed.

From UIWindow documentation:

The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window. If the window has an existing view hierarchy, the old views are removed before the new ones are installed.

So you have to make sure that you add your view into the window hierarchy after the rootViewController is set.

For example when the first controller is loaded - you can lazy load that view only once.

like image 37
KoCMoHaBTa Avatar answered Mar 28 '23 07:03

KoCMoHaBTa