简体   繁体   中英

Issues presenting UIActivityViewController

I want to give a share screen throughout my app. I am using UIActivityViewController for that purpose. The problem is, as per your location in the app, the current root view controller can be of kind UINavigationController (Case1) or UIViewController (Case2).

I can present UIActivityViewController using

[viewController presentViewController:viewController animated:YES completion:nil];

But I have to get currently visible UIViewController of UINavigationController in (Case1), and root view controller itself in (Case2).

But how to detect which kind of root view controller is present & code accordingly?

Thanks.

Try:

UIViewController *root = [[[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0] nextResponder];

and then:

if ([root isKindOfClass:[UINavigationController class]]) {
    // Navigation Controller
} else {
    // The other one
}

that should tell you which one is presented.

Use the above method to detect for a UINavigationControler;

 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//If this will be called it is a navigation controller
}

use performselector to start and stop rorating activity indicater

Here AI is activity indicater variable name

    [self performSelector:@selector(animateAI) withObject:self afterDelay:0.1];

    [self performSelector:@selector(stopAI) withObject:self afterDelay:0.9];

-(void)animateAI
{
    [AI startAnimating];

}

-(void)stopAI
{
   [AI stopAnimating];
}

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