【发布时间】:2012-07-31 08:50:24
【问题描述】:
我正在尝试在 UIAlertView 中创建一个 UIPickerView,我写了以下代码
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];
但在运行时,pickerView 的大小不适合警报视图,它看起来如图所示。
我该如何解决这个问题? 提前致谢。
我解决了,发现我有如下代码
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 300;
return sectionWidth;
}
当我删除它时,它修复了。 :) 感谢所有试图帮助我的人,我为我的错误感到非常抱歉。 :$
【问题讨论】:
-
你可以改变选择器视图的宽度
-
我试图减少它,但它减少了右侧的“选择器边缘”线,并且选择器的剩余部分通过了警报的边缘
标签: iphone ios ipad uipickerview