1

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];
}
dizy
  • 7,951
  • 10
  • 53
  • 54
  • u need to diclear your Button as a globle and when you present UIActivityViewController you just hide like button.hidden=True and when dismiss then button.hidden=False – Nitin Gohel Oct 15 '12 at 08:51
  • I'm not trying to hide the buttons, it's automatically hiding them as a side effect of displaying the UIActivityViewController. I don't want them to hide. – dizy Oct 15 '12 at 23:52
  • Try this link may be helped you .... 1. http://stackoverflow.com/questions/2971483/hide-uitoolbar-uibarbuttonitems 2. http://stackoverflow.com/questions/276861/how-can-i-dynamically-hide-a-button-from-a-view 3. https://developer.apple.com/library/ios/#documentation/uikit/reference/UIToolbar_Class/Reference/Reference.html – Eye movements Oct 15 '12 at 09:23
  • I'm not trying to hide the buttons, it's automatically hiding them as a side effect of displaying the UIActivityViewController. I don't want them to hide. – dizy Oct 15 '12 at 23:52
  • @dizy ok i got it your point , but actually u have add the screenshot after the my ans... – Eye movements Oct 16 '12 at 04:31

2 Answers2

0

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;
}
dizy
  • 7,951
  • 10
  • 53
  • 54
0

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]; }

Ash
  • 5,525
  • 1
  • 40
  • 34