Muh*_*edy 5 uipickerview uiactionsheet ipad ios
我有一个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];
}
Run Code Online (Sandbox Code Playgroud)
// 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";
}
Run Code Online (Sandbox Code Playgroud)
但是当更改上面的代码以在ActionSheet中添加PickerView时,它只显示 ActionSheet 的标题,但里面没有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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3572 次 |
| 最近记录: |