UIActionSheet 中的 UIPickerView:UI 冻结
Posted
技术标签:
【中文标题】UIActionSheet 中的 UIPickerView:UI 冻结【英文标题】:UIPickerView in a UIActionSheet: UI freezes 【发布时间】:2012-01-23 05:29:18 【问题描述】:每当我触发带有UIPickerView
的UIActionSheet
时,我的ios 应用程序就会冻结。选择器滚轮滚动正常,直到我尝试点击UIActionSheet
上的“完成”按钮,此时 UI 冻结。但是,XCode 并没有在程序中记录任何类型的崩溃,所以我很困惑。
以前有没有其他人遇到过这个问题?我该如何解决?
【问题讨论】:
【参考方案1】:我从来没有遇到过这种类型的问题。我认为这个问题可以帮助您解决问题。我以同样的方式使用了 PickerView
UIActionSheet *actionSheet;
NSString *pickerType;
- (void)createActionSheet
if (actionSheet == nil)
// setup actionsheet to contain the UIPicker
actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDone:)];
[barItems addObject:doneBtn];
[doneBtn release];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
[actionSheet addSubview:pickerToolbar];
[pickerToolbar release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
-(IBAction)BtnPressed:(id)sender
[self createActionSheet];
pickerType = @"picker";
select = NO;
UIPickerView *chPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
chPicker.dataSource = self;
chPicker.delegate = self;
chPicker.showsSelectionIndicator = YES;
[actionSheet addSubview:chPicker];
sessoTxt.text = [sessoArray objectAtIndex:0];
[chPicker release];
#pragma mark UIPickerViewDelegate Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
return 1;
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
int count;
if ([pickerType isEqualToString:@"picker"])
count = [array count];
return count;
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
NSString *string;
if ([pickerType isEqualToString:@"picker"])
string = [array objectAtIndex:row];
return string;
// Set the width of the component inside the picker
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
return 300;
// Item picked
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
select = YES;
if ([pickerType isEqualToString:@"picker"])
Txt.text = [array objectAtIndex:row];
- (void)pickerDone:(id)sender
if(select == NO)
if ([pickerType isEqualToString:@"picker"])
Txt.text = [array objectAtIndex:0];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
[actionSheet release];
actionSheet = nil;
【讨论】:
以上是关于UIActionSheet 中的 UIPickerView:UI 冻结的主要内容,如果未能解决你的问题,请参考以下文章