When presenting from a bar button item, you usually want to disable all other buttons on your toolbar until the action sheet is dismissed.
I think the simplest way to do this is to modify the UIToolbar class. You'll need a way to get hold of the actionsheet, perhaps by saving it in the app delegate.
Make a file UIToolbar+Modal.m, like this:
@implementation UIToolbar (Modal)
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
UIActionSheet *mySheet = [[[UIApplication sharedApplication] delegate] myActionSheet];
if ([mySheet isVisible]) return nil;
else return hitView;
}
@end
The .h file doesn't need to contain anything special
@interface UIToolbar (Modal) {
}
@end
By the way, before finding this solution I tried assigning an empty array to passthroughViews, that you can access as (originally) described by stalinkay, but this doesn't in fact work (in addition to being undocumented).
The other ways to do this all have disadvantages - either you have to handle orientation changes, or the toolbar buttons look like they press down when in fact the only action taken is to dismiss the actionsheet.
UPDATE
As of iOS 4.3 this no longer works. You need to subclass:
UIToolbarWithModal.h
#import <Foundation/Foundation.h>
@interface UIToolbarWithModal : UIToolbar {
}
@end
Remember when you create the action sheet you need to keep it accessible, perhaps in your app delegate - in this example in the myActionSheet property.
UIToolbarWithModal.m
#import "UIToolbarWithModal.h"
#import "MyDelegate.h"
@implementation UIToolbarWithModal
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
UIActionSheet *mySheet = [[[UIApplication sharedApplication] delegate] myActionSheet];
if ([mySheet isVisible]) return nil;
else return hitView;
}
@end
Then just use UIToolbarWithModal in your code where you would have used UIToolbar before.