我們有一個UIActionSheet與許多選項。在iPad上的iOS 7中,當滾動列表時,它會鬼影原始值。這是iPad 7的缺陷還是我們可以做出改變? iOS 6 iPad和iPhone對我們來說看起來還不錯。UIActionSheet與許多項目疊加文本
//
// 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
考慮使用另一個接口(彈出窗口中的表視圖)。行動表從來不打算像這樣被敲打,而且你真的只是把它當作懶惰的人的桌子來使用。 – matt
我會說你濫用UIActionSheet。這意味着用戶可以選擇不超過10個操作項目。當然,這不是一個很難的數字,但在行動表中顯示整個列表並不是一個好主意。我會創建一個單獨的視圖控制器,它具有一個允許用戶選擇的表視圖(實質上是一個操作表)。 –
我發佈後,我幾乎編輯它以發表評論,以保護我的信譽。通常這將是2-4項,但我們有一個客戶以奇怪的方式使用它。我發佈的只是示例代碼,以展示我認爲是一個錯誤。 –