Get name of current view residing in a UIWindow
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
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);
}
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.
精彩评论