私はUIPickerViewを持っていて、iPadのUIActionSheet内に表示する必要があります(iPadではなく、iPhoneでは非常に簡単です)。iPadのUIActionSheet内にUIPickerViewを追加する
私は、次のコード実行をクリックすると、表示上のボタンをしました:
- (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のヘッダーだけが表示されますが、その中に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];
}
私はPickerView initLineを 'UIPickerView * picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0,320,469)];に変更しましたが、今はActionSheet内のPickerViewの非常に小さな部分を見ることができますが、非常に小さな正方形として、どのように私はそれを大きくすることができます、私はその幅と高さを変更しようとしているが動作していないようです! –
cancelButtonTitleをNSStringに設定して、サイズが変更されているかどうかを確認してください。 –
私はうんざりします。代わりに 'UITableViewController'を使って' UIPopoverController'を使うつもりです! .. とにかくありがとう! –