包含许多项目的UIActionSheet覆盖文本

时间:2014-05-21 19:54:07

标签: ios ipad ios7 uiactionsheet

我们有一个有很多选项的UIActionSheet。在iPad上的iOS 7中滚动列表时,它会重置原始值。这是iPad 7的错误还是我们可以做出改变? iOS 6 iPad和iPhone看起来不错。

before scrolling

after scrolling

//
//  ViewController.m
//  AlertViewTest
//
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    _data = [NSMutableArray new];
    [_data addObject:@"Arthur"];
    [_data addObject:@"Bertha"];
    [_data addObject:@"Cristobal"];
    [_data addObject:@"Dolly"];
    [_data addObject:@"Edouard"];
    [_data addObject:@"Fay"];
    [_data addObject:@"Gonzalo"];
    [_data addObject:@"Hanna"];
    [_data addObject:@"Isaias"];
    [_data addObject:@"Josephine"];
    [_data addObject:@"Kyle"];
    [_data addObject:@"Laura"];
    [_data addObject:@"Marco"];
    [_data addObject:@"Nana"];
    [_data addObject:@"Omar"];
    [_data addObject:@"Paulette"];
    [_data addObject:@"Rene"];
    [_data addObject:@"Sally"];
    [_data addObject:@"Teddy"];
    [_data addObject:@"Vicky"];
    [_data addObject:@"Wilfred"];

    [_data addObject:@"Ana"];
    [_data addObject:@"Bill"];
    [_data addObject:@"Claudette"];
    [_data addObject:@"Danny"];
    [_data addObject:@"Erika"];
    [_data addObject:@"Fred"];
    [_data addObject:@"Grace"];
    [_data addObject:@"Henri"];
    [_data addObject:@"Ida"];
    [_data addObject:@"Joaquin"];
    [_data addObject:@"Kate"];
    [_data addObject:@"Larry"];
    [_data addObject:@"Mindy"];
    [_data addObject:@"Nicholas"];
    [_data addObject:@"Odette"];
    [_data addObject:@"Peter"];
    [_data addObject:@"Rose"];
    [_data addObject:@"Sam"];
    [_data addObject:@"Teresa"];
    [_data addObject:@"Victor"];
    [_data addObject:@"Wanda"];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)showAlert:(id)sender {
    if([self.actionSheet isVisible]) {
        [self.actionSheet dismissWithClickedButtonIndex:[self.actionSheet cancelButtonIndex] animated:YES];

        self.actionSheet.delegate = nil;
        self.actionSheet = nil;

        return;
    }

    if(nil == self.actionSheet) {
        self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select one"
                                                       delegate:self
                                              cancelButtonTitle:nil
                                         destructiveButtonTitle:nil
                                              otherButtonTitles:nil];


        if(![self shouldPresentActionSheet:self.actionSheet]) {
            self.actionSheet = nil;
            return;
        }


        [self.actionSheet setCancelButtonIndex:[self.actionSheet addButtonWithTitle:NSLocalizedString(@"Cancel", @"Cancel")]];

    }

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [self.actionSheet showFromBarButtonItem:self.button animated:YES];
    } else {
        [self.actionSheet showFromToolbar:self.toolbar];
    }
}

-(BOOL)shouldPresentActionSheet:(UIActionSheet *)actionSheet
{
    if(actionSheet == self.actionSheet) {
        if([self.data count] == 0) {
            return NO;
        }
        for(NSString *d in self.data) {
            [self.actionSheet addButtonWithTitle:d];
        }

    }
    return YES;
}

@end

2 个答案:

答案 0 :(得分:0)

评论中的

@Flores是对的,以下是解决此问题的方法:

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

答案 1 :(得分:-1)

它应该是这样的

//view did load stuff

- (IBAction)showAlert:(id)sender {
self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title Here"
                                                         delegate:self
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

// ObjC Fast Enumeration
for (NSString *title in _data) {
    [actionSheet addButtonWithTitle:title];
}

[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = [_data count];

[actionSheet showInView:self.view];

Source