Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a UIPickerView inside UIActionSheet in iPad

I've a UIPickerView and need to make it show inside a UIActionSheet in iPad (it works very straightforward in iPhone, not in iPad).

I've a button on the View when I click on I execute the following code:

- (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];    
}

// the PickerView delegate and datasource functions:

// 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";
}

But When change the above code to add the PickerView inside an actionSheet, It shows only the header of the ActionSheet but without the PickerView inside it!

The modified code as follows:

- (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];

}
like image 457
Muhammad Hewedy Avatar asked Nov 13 '22 12:11

Muhammad Hewedy


1 Answers

I stuck, I gonna use a UIPopoverController with a UITableViewController inside instead! .. Thanks anyway!

like image 143
Muhammad Hewedy Avatar answered Nov 16 '22 02:11

Muhammad Hewedy