【发布时间】:2012-02-14 21:14:46
【问题描述】:
在 UIActionSheet 中有一个 UIPickerView 是否可以接受(也就是 Apple 认为可以接受)?
【问题讨论】:
标签: ios cocoa-touch app-store uipickerview uiactionsheet
在 UIActionSheet 中有一个 UIPickerView 是否可以接受(也就是 Apple 认为可以接受)?
【问题讨论】:
标签: ios cocoa-touch app-store uipickerview uiactionsheet
是的,这是完全可以接受的。在某种程度上它甚至受到鼓励。
示例代码:HERE 由 Erica Sadun 在她的《iPhone Developer's cookbook》一书中编写。第11章秘方21
【讨论】:
是的。可以接受。
设置 UIPickerView 的框架
将 UIPickerView 添加到 actionView
我记得,在这种情况下,actionView 将是全屏的
UIActionSheet *actionView = [[UIActionSheet alloc] initWith...];
UIPickerView *pickerView = [UIPickerView alloc] init...];
pickerView.frame = CGRect(....);
[actionView addSubview:pickerView];
[pickerView release];
[actionView showInView:theView];
[actionView release];
【讨论】:
应该这样做:
NSString *title = @"\n\n\n\n\n\n\n\n\n\n\n\n"; // <--- Taken from Erica Sadun´s CookBook
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[actionSheet setBounds:CGRectMake(0,0,320,485)];
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
[picker setDataSource:self];
[picker setDelegate:self];
[picker setShowsSelectionIndicator:YES];
[actionSheet addSubview:picker];
[actionSheet showFromTabBar:[[self tabBarController] tabBar]];
请记住,您必须设置 UIPickerView 的 dataSource 和 delegate 。
【讨论】: