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.
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. :$