UIActionSheet中的UIPickerView:UI冻结



每当我触发一个包含UIPickerViewUIActionSheet时,我的iOS应用程序就会冻结。选择器滚轮会一直滚动,直到我尝试点击UIActionSheet上的"完成"按钮,此时UI就会冻结。然而,XCode没有在程序中注册任何类型的崩溃,所以我很困惑。

以前有其他人遇到过这个问题吗?我该如何解决?

我从来没有遇到过这种类型的问题。我认为这个是帮你解决问题的。我使用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;
}
}

最新更新