I have a question regarding the UIActionSheet on the iPad.
When I present an action sheet from presentFromBarButtonItem:animated:
and present another one after that (by tapping on another UIBarButtonItem on the same UIToolbar), the original UIActionSheet stays open.
It doesn't look particularly good.
I've tried iterating through self.view.subviews
and casting the view to a UIActionSheet and calling its appropriate dismissWithClickedButtonIndex:animated:
method, however it doesn't work.
For example:
- (void)pressBarButtonItem {
for (UIView *view in self.view.subviews) {
[(UIActionSheet *)view dismissWithClickedButtonIndex:-1 animated:YES];
}
}
Any help appreciated.
I think you mean showFromBarButtonItem:animated:
instead of presentFromBarButtonItem:animated:
?
The action sheet doesn't dismiss automatically on the iPad when you tap on another toolbar item because the toolbar is added to the action sheet's list of passthrough views.
Keep a reference to the action sheet in a property. After calling showFromBarButtonItem, save it in the property using self.itemFooActionSheet = actionSheet;
.
Before showing another action sheet from another item, call dismissWithClickedButtonIndex on itemFooActionSheet. After dismissing it, you may also want to release itemFooActionSheet and set it to nil so it doesn't hang around in memory.
Additionally, it's possible that the code will try to show item Foo's action sheet again while it's already displayed. In the method where you show item Foo's action sheet, first check if self.itemFooActionSheet is not nil and if so, just show it without re-creating it or dismiss+destroy the current action sheet and build a new one (the old one might contain outdated information).