Get the name of the current view located in UIWindow

Let's say I add a new view to my UIWindow

[windowRoot addSubview:MyNewView.view];

Is it possible to get the name of this view later if I have a link to windowRoot? Sort of:

[windowRoot getCurrentViewName]  

thank

+3
source share
3 answers

UIWindow there is a UIView, so you can do something like this to get it as subviews:

for (UIView *view in windowRoot.subviews) {
    NSLog(@"View: %@", view);
}
+4
source

Your question seems to imply a big design problem. I assume that "name" means the name of the variable related to the new view? This variable should actually be an instance variable of your window controller.

0
NSUserDefaults *savedData = [NSUserDefaults standardUserDefaults];

NSString *currentPage = [NSString stringWithFormat:@"%@", self.nibName];

[savedData setObject:currentPage forKey:@"lastViewAccessed"];

//self.nibName will get you what you the name of the view.
0

Source: https://habr.com/ru/post/1741666/


All Articles