Get name of current view residing in a UIWindow
-
27-09-2019 - |
Question
Let's say I add a new view to my UIWindow
[windowRoot addSubview:MyNewView.view];
Is it possible to retrieve the name of that view later on if I have reference to windowRoot? Something like:
[windowRoot getCurrentViewName]
Thank You
Solution
UIWindow
is a UIView
, so you can do something like this to get the subviews of it:
for (UIView *view in windowRoot.subviews) {
NSLog(@"View: %@", view);
}
OTHER TIPS
Your question seems to imply a bigger design issue. I assume by "name" you mean the name of the variable referring to new view? That variable should actually be an instance variable of your window controller.
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow