Pregunta

hiding buttonsThis looks like a bug to me, but maybe someone can think of a workaround?

Basically if you have a custom UIToolbar, its button items will automatically hide when you present a UIActivityViewController, and reappear when you dismiss it. This is only the case on the iPhone. Being that UIActivityViewController doesn't hide the entire screen it just looks weird that buttons disappear behind the dimmed screen.

To replicate, simply start a single view project and use the following code on the view controller:

- (void)viewDidLoad {
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(didTapAction)];
    toolbar.items = [NSArray arrayWithObject:button];
    [self.view addSubview:toolbar];
}

- (void)didTapAction {
    NSArray *items = [NSArray arrayWithObjects:@"Text", nil];
    UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    [self presentViewController:sharing animated:YES completion:nil];
}
¿Fue útil?

Solución

Found a workaround. Simply get rid of all the items before presenting, and add them back right after.

- (void)didTapAction {
    NSArray *items = [NSArray arrayWithObjects:@"Text", nil];
    UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    NSArray *barItems = toolbar.items;
    toolbar.items = nil;
    [self.navigationController presentViewController:sharing animated:YES completion:nil];
    toolbar.items = barItems;
}

Otros consejos

know it is quite old thread for but those who look this page for solution, here you go :

With iOS7, you can use this approach to show/hide your toolbar button :

if(// your code Condition) 

{ self.toolbarBtn1.enabled = YES; self.toolbarBtn1.tintColor = nil; } else { self.toolbarBtn1.enabled = NO; self.toolbarBtn1.tintColor = [UIColor clearColor]; }

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top