I have this ad class which contains an UIImageView. I've added an instance of the class to my appdelegate onto the "window" view.
Now, I want to, when the user taps the ad, push my "detailedViewController" onto the current navigation controller, which all of my tab bar items contain. I don't know if it is possible.
Perhaps, I should just add my advertisement class to every view controller for every nav controller. However, if the user pushes or changes a view controller it would r开发者_如何学编程eset the class.
I just want to overlay the ad once.
EDIT:
Let me rephrase, can I from the app delegate and from my object know which tab bar item is selected? If I can determine which tab bar item is selected I can point to the appropriate nav controller instance.
The easyiest way would be to present your DetailVC as a ModalView which also makes sense in semantics.
Yes, it is possible to detect which tab is selected but it is easier to use the selectedViewController
-property of UITabBarController
.
UIViewController *curVC = myTabBarController.selectedViewController;
if([curVC isKindOfClass:UINavigationController.class])
{
UINavigationController *nav = (UINavigationController*)curVC;
[nav push...];
}
else
{
// do sth else: go to webpage for instance
}
Whoever owns the tab bar controller can do
[myTabBarController selectedIndex];
or
[myTabBarController selectedViewController];
The first one returns the index of the selected item, the second one the actual view controller, you might be better off with the first one.
精彩评论