objective-c - UIActionSheet 中的 UIPickerView : UI freezes

标签 objective-c ios user-interface uipickerview uiactionsheet

每当我触发其中包含 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;

}

}

关于objective-c - UIActionSheet 中的 UIPickerView : UI freezes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967538/

相关文章:

如果应用程序在后台,iOS 会检测屏幕截图

ios - 设置新的 UITabBar 框架时,UITabBarItems 消失

iOS 如何知道按下了哪个按钮 CollectionView 与自定义委托(delegate)

android - 如何对齐屏幕底部的 View ?

ios - 如何获取每30个:00(30 minutes) from current time to 10:30 pm的时间间隔

ios - 用于类消息的 Objective-C 宏

ios - swift 3 使用图层通过绘制 "clear"行来显示图像

ios - 在 iOS 中分析文本到语音的字符串

javascript - 如何配置 dxFileUploader 像一个简单的按钮一样显示?

c# - 如何在WPF中绘制数字信号?