15

On the iPad new ios 7 UIActionSheet is not correctly displayed with lots of buttons.

Not cleaning background of UIActionSheet on scrolling. The buttons seem frozen in background UIActionSheet.

screenshot with problem

My code :

UIActionSheet *popupQuery = [[UIActionSheet alloc]; 
for (int i=0; i<[ParamAllList count]; i++) 
{ 
    NSMutableDictionary *Param = [ParamAllList objectAtIndex:i]; 
    [popupQuery addButtonWithTitle:[Param valueForKey:@"name"]]; 
    [[[popupQuery valueForKey:@"_buttons"] objectAtIndex:[[popupQuery valueForKey:@"_buttons"] count]-1] setImage:[UIImage imageNamed:@"add40icon.png"] forState:UIControlStateNormal];
} 
popupQuery.actionSheetStyle = UIActionSheetStyleAutomatic; 
[popupQuery showFromRect:Button_Settings.frame inView:Button_Settings.superview animated:YES];
Jordan Montel
  • 8,227
  • 2
  • 35
  • 40
Constantinus
  • 169
  • 1
  • 7
  • please add code when you create your UIActionSheet – Jordan Montel Oct 02 '13 at 15:51
  • UIActionSheet *popupQuery = [[UIActionSheet alloc]; for (int i=0; i<[ParamAllList count]; i++) { NSMutableDictionary *Param = [ParamAllList objectAtIndex:i]; [popupQuery addButtonWithTitle:[Param valueForKey:@"name"]]; [[[popupQuery valueForKey:@"_buttons"] objectAtIndex:[[popupQuery valueForKey:@"_buttons"] count]-1] setImage:[UIImage imageNamed:@"add40icon.png"] forState:UIControlStateNormal]; } popupQuery.actionSheetStyle = UIActionSheetStyleAutomatic; [popupQuery showFromRect:Button_Settings.frame inView:Button_Settings.superview animated:YES]; – Constantinus Oct 03 '13 at 10:13
  • I am basically doing the same thing w/o the picture: even if I do this: UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"test" delegate:self cancelButtonTitle:@"" destructiveButtonTitle:@"Cancel" otherButtonTitles:@"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi",nil]; It messes up like this.... Something to do with the amount of buttons. – dan Oct 03 '13 at 10:55
  • when the amount of buttons fit without scrolling - then everything is OK. when a scroll buttons - then the background fades. Ran through the subviews of UIActionSheet - and realized that object UIActionSheet contains only label and buttons (no tableView or to scrollView) - hence this bug system. – Constantinus Oct 04 '13 at 10:17
  • Did you file a radar for this? – Ryan Poolos Jan 15 '14 at 18:36
  • I filed a rdar://15828155 for this and verified it unfixed in the latest iOS 7.1 beta 3 release. – Ryan Poolos Jan 16 '14 at 18:49

2 Answers2

24

This was my workaround for the actionSheet delegate:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    actionSheet.backgroundColor = [UIColor whiteColor];
    for (UIView *subview in actionSheet.subviews) {
        subview.backgroundColor = [UIColor whiteColor];
    }
}

Based off of this answer: Change Text color in UIActionSheet Buttons

Community
  • 1
  • 1
bubastis
  • 271
  • 1
  • 5
  • 2
    - (void)willPresentActionSheet:(UIActionSheet *)actionSheet { int count=0; for (UIView *object in actionSheet.subviews) { if ([[[object class] description] isEqualToString:@"UIView"]) { count++; if (count==2) { object.backgroundColor = [UIColor whiteColor]; break; } } } } – Constantinus Oct 10 '13 at 18:34
  • thanks))))) my code leaves a little bit transparent background. – Constantinus Oct 10 '13 at 18:36
  • 2
    Nice work around, it is a shame that such problem exists. Thanks. – mashdup Oct 21 '13 at 13:24
2

Funny thing - this bug still exists in iOS 7.1beta4 :)
And doesn't appear in iPhone implementation, only iPad...

And its origin is quite strange - "blurry" effect is showing when an UIActionSheet has so many items, so it have to put these in an UITableView like container, but unfortunately this view container is put twice (and it isn't the same instance). So we need to leave only one and remove others.

Antoher thing we need to correct is the UITableView height.

Below my fix - to implement in UIActionSheetDelegate -(void)willPresentActionSheet:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ) {
        if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
            // fix for iOS7 iPad UIActionSheet presentation when content need to scroll
            // and scrolled view appears with unnecessary copies, remove not needed ones
            // and set proper tableview height too
            int count = 0;
            for (UIView *subview in actionSheet.subviews) {
                if( [subview isMemberOfClass:[UIView class]] ) {
                    if( ++count == 1 ) {
                        // process only first view
                        for( UIView *subsubview in subview.subviews ) {
                            if( [subsubview isKindOfClass:[UITableView class]] ) {
                                // fix table view height
                                UITableView *tableView = (UITableView*)subsubview;

                                CGRect tableViewFrame = tableView.frame;
                                tableViewFrame.size.height -= subview.frame.origin.y;

                                tableView.frame = tableViewFrame;
                            }
                        }
                    } else {
                        // remove unnecessary view
                        [subview removeFromSuperview];
                    }
                }
            }
        }
    }
}
shc
  • 369
  • 2
  • 8