【发布时间】:2012-01-04 15:13:31
【问题描述】:
我有一个 UIPickerView,需要让它在 iPad 的 UIActionSheet 中显示(它在 iPhone 中非常简单,而不是在 iPad 中)。
当我点击执行以下代码时,我在视图上有一个按钮:
- (IBAction) buttonPressed:(id)sender
{
NSLog(@"I am pressed");
UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
[self.view addSubview:picker];
}
// PickerView 委托和数据源函数:
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 5;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return @"One";
}
但是当更改上面的代码在actionSheet中添加PickerView时,它只显示了ActionSheet的header,但里面没有PickerView!
修改后的代码如下:
- (IBAction) buttonPressed:(id)sender
{
NSLog(@"I am pressed");
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"My PickerView"
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
[actionSheet addSubview:picker];
[actionSheet showFromRect:CGRectMake(0, 0, 320, 469) inView:self.view animated:NO];
}
【问题讨论】:
标签: ios ipad uipickerview uiactionsheet