简体   繁体   中英

Adding UIView to UIWindow not working

I am trying to add a UIView to UIWindow using the appDelegate I am using this code:

NSArray *myViewArray = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil];

UIView *myView = myViewArray[0];

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

myView.frame = CGRectMake(0, 0, 258, 564);
[myView setTag:100];
[window addSubview:myView];

However this doesn't work. If I add it to my self.view it works fine. However, I want this view to be onto of all other views when it appears.

What am I doing wrong here?

Edit

I used code from my last SO question: How to add a UIImage below UIBarButton item

There it worked fine, no problems.

However in this new project which only has a viewDidLoad method and one controller its not working.

确保在初始化窗口后添加子视图,设置其rootViewController并调用makeKeyAndVisible。

尝试使用[window bringSubViewToFront:myView];

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