简体   繁体   中英

pushing onto navigation stack not within the nav controller

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

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM