1

I'm trying to create an UIPickerView in UIAlertView, I wrote the following code

UIAlertView *alert = [[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];

alert.title = @"Preferences";
alert.message = @"\n\n\n\n\n\n\n";
alert.delegate = self;
[alert addButtonWithTitle:@"Cancel"];
[alert addButtonWithTitle:@"OK"];


UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
myPickerView.autoresizingMask = UIAlertViewStyleDefault;

myPickerView.frame = CGRectMake(10, 40, 250, 150);

[alert addSubview:myPickerView];

[alert show];

but when run, the pickerView size is not fit the alert view, it looks as shown in the image.

here image

how can I solve this issue? Thanks in advance.


I solved it, I discovered that I have the following code

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component    {
int sectionWidth = 300;

return sectionWidth;
}

when I removed this, It fixed. :) thanks for everyone tried to help me, and I'm very sorry for my mistake. :$

user1553381
  • 415
  • 2
  • 13
  • 30

4 Answers4

1

I had a requirement similar to this. But I couldn't succeed it using 'UIPickerView'. So I moved to 'AFPickerView'. May be that would help you too!!

Nina
  • 1,579
  • 2
  • 21
  • 51
0

You can not resize pickerView height only change width and x and y coordinates Or you have to make alertview big eno

0

I'm seriously questioning this style. Besides, I dont think you can actually change the size of an UIAlertView. I suggest you perform a modal segue with form sheet presentation to show a UIView wich you placed an UIPickerview on with some buttons to confirm or cancel. You can do this using a StoryBoard or program it manually.

Pieter Gunst
  • 139
  • 5
  • but the requirements of my project tells me to perform this style :S its important to add a pickerView in the alerView :S – user1553381 Jul 31 '12 at 09:13
  • The documentation says: "The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified." Meaning that the UIAlertView will adapt itself in size for your message to fit, but you can not force it to be a certain size nor should the view hierarchy be modified. – Pieter Gunst Jul 31 '12 at 09:20
0

Change the Width in xib.For this you need to open the Xib in XML form and find that PickerView and change the width and save,run.Hope This Will Work!!

Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75