开发者

pushing onto navigation stack not within the nav controller

开发者 https://www.devze.com 2023-04-07 04:22 出处:网络
I have this ad class which contains an UIImageView. I\'ve added an instance of the class to my appdelegate onto the \"window\" view.

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.

0

精彩评论

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