开发者

How to the grab the highest level Superview in iPhone App?

开发者 https://www.devze.com 2023-01-26 06:43 出处:网络
I want to be able to grab the main UIView for the application.So far, I have been calling [[[self.view superview] superview] superview] to traverse up the chain (or down, depending on how you look at

I want to be able to grab the main UIView for the application. So far, I have been calling [[[self.view superview] superview] superview] to traverse up the chain (or down, depending on how you look at it). The problem with this is that it is possible that I can't be absolutely sure the number of levels up开发者_JAVA百科 I need to go. Is there a way to:

  1. Go directly to the highest level UIView in an iPhone application?

or, if not,

  1. Check to see if the current superview is the highest level UIView in the app?


I'm not sure that it's what your are looking for in the first place, but it can help.

If you are trying to find the top view in order to add a subview, like say a popup or other, you can use UIWindow, which is in some way, the top level view:

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
[window addSubview:yourView];


Just pulling this off the top, something like checking if the superview property of the current view is null? If it is I guess we may presume that it is the root view.

0

精彩评论

暂无评论...
验证码 换一张
取 消