开发者

Get name of current view residing in a UIWindow

开发者 https://www.devze.com 2022-12-27 12:56 出处:网络
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

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.
0

精彩评论

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

关注公众号