2013-09-26 11 views
15

Sul nuovo iPad UIActionSheet ios 7 non viene visualizzato correttamente con molti pulsanti.Xcode iPad UIActionSheet con molti pulsanti non visualizzati correttamente iOS7

Non si pulisce lo sfondo di UIActionSheet sullo scorrimento. I pulsanti sembrano congelati in background UIActionSheet.

screenshot with problem

Il mio codice:

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]; 
+0

si prega di aggiungere il codice quando si crea l'UIActionSheet –

+0

UIActionSheet * popupQuery = [[UIActionSheet alloc]; per (int i = 0; i <[numero ParamAllList]; i ++) { NSMutableDictionary * Param = [ParamAllList objectAtIndex: i]; [popupQuery addButtonWithTitle: [Param valueForKey: @ "nome"]]; [[[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 animato: YES]; – Constantinus

+0

Fondamentalmente sto facendo la stessa cosa senza l'immagine: anche se faccio questo: UIActionSheet * popupQuery = [[UIActionSheet alloc] initWithTitle: @ "test" delegato: self cancelButtonTitle: @ "" distructiveButtonTitle: @ "Annulla" otherButtonTitles : @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao" , @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao" , @ "ciao", @ "ciao", @ "ciao", @ "ciao", @ "ciao", nullo]; Si incasina come questo .... Qualcosa a che fare con la quantità di pulsanti. – dan

risposta

24

Questa era la mia soluzione per il delegato actionSheet:

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

base al largo di questa risposta: Change Text color in UIActionSheet Buttons

+2

- (void) willPresentActionSheet: (UIActionSheet *) actionSheet { int count = 0; per (oggetto UIView * in actionSheet.subviews) { if ([[[classe oggetto] descrizione] isEqualToString: @ "UIView"]) { count ++; if (count == 2) { object.backgroundColor = [UIColor whiteColor]; interruzione; } } } } – Constantinus

+0

grazie))))) il mio codice lascia uno sfondo un po 'trasparente. – Constantinus

+2

Bel lavoro, è un peccato che questo problema esista. Grazie. – mashdup

2

cosa divertente - questo bug bug l esiste in iOS 7.1beta4 :)
E non appare nella realizzazione iPhone, iPad solo ...

e la sua origine è molto strano - "sfocata" effetto sta mostrando quando un UIActionSheet ha tanti articoli quindi deve inserirli in un contenitore simile a UITableView, ma sfortunatamente questo contenitore di viste viene inserito due volte (e non è la stessa istanza). Quindi dobbiamo lasciare solo uno e rimuovere gli altri.

La cosa di Antoher che dobbiamo correggere è l'altezza UITableView.

Di seguito il mio fix - da implementare 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]; 
        } 
       } 
      } 
     } 
    } 
} 
+0

Non funziona per me (iOS 7.1), il risultato è solo uno sfondo bianco sfocato (senza TableView). – osxdirk

Problemi correlati