2013-09-26 71 views
15

Trên iPad ios 7 UIActionSheet mới không hiển thị chính xác với nhiều nút.Xcode iPad UIActionSheet với nhiều nút không hiển thị chính xác iOS7

Không làm sạch nền của UIActionSheet khi cuộn. Các nút có vẻ bị đóng băng trong nền UIActionSheet.

screenshot with problem

Mã của tôi:

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

xin thêm mã khi bạn tạo bạn UIActionSheet –

+0

UIActionSheet * popupQuery = [[UIActionSheet alloc]; cho (int i = 0; i <[số ParamAllList]; i ++) { NSMutableDictionary * Param = [đối tượng ParamAllListAtIndex: 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 hoạt ảnh: YES]; – Constantinus

+0

Tôi về cơ bản đang làm điều tương tự với hình ảnh: ngay cả khi tôi làm điều này: 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]; Nó messes lên như thế này .... Một cái gì đó để làm với số lượng các nút. – dan

Trả lời

24

Đây là cách giải quyết của tôi cho các đại biểu actionSheet:

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

Dựa tắt của câu trả lời này: Change Text color in UIActionSheet Buttons

+2

- (void) willPresentActionSheet: (UIActionSheet *) actionSheet { int count = 0; cho (đối tượng UIView * đang hoạt độngSheet.subviews) { nếu ([[[[lớp đối tượng] mô tả] isEqualToString: @ "UIView"]) { đếm ++; if (count == 2) { object.backgroundColor = [UIColor whiteColor]; ngắt; } } } } – Constantinus

+0

cảm ơn))))) mã của tôi để lại một chút nền trong suốt. – Constantinus

+2

Làm việc tốt xung quanh, nó là một sự xấu hổ rằng vấn đề như vậy tồn tại. Cảm ơn. – mashdup

2

điều Funny - lỗi này stil l tồn tại trong iOS 7.1beta4 :)
Và không xuất hiện trong triển khai iPhone, iPad chỉ ...

Và nguồn gốc của nó là khá kỳ lạ - "mờ" hiệu ứng được hiển thị khi một UIActionSheet có rất nhiều mặt hàng , do đó, phải đặt các mã này vào một vùng chứa như UITableView, nhưng tiếc là vùng chứa chế độ xem này được đặt hai lần (và nó không phải là cùng một ví dụ). Vì vậy, chúng ta chỉ cần để lại một và loại bỏ những người khác.

Điều Antoher chúng ta cần sửa là chiều cao UITableView.

Dưới sửa chữa của tôi - để thực hiện trong 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

Không hoạt động với tôi (iOS 7.1), kết quả chỉ là một nền trắng mờ (không có tableView). – osxdirk