【问题标题】:how to manage uipickerview in uiactionsheet如何在uiactionsheet中管理uipickerview
【发布时间】:2013-08-05 08:28:53
【问题描述】:

我正在尝试在 UIActionSheet 中显示 UIPickerView。从下面提到的代码来看,它在纵向模式下效果很好,但在横向模式下看起来很有线。 (我的应用程序也支持 iPhone 4/5 n 横向)。 我做错了什么?

 actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                              delegate:nil
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];


    CGRect pickerFrame=CGRectMake(0, 40, 0, 0);

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;


    [actionSheet addSubview:pickerView];

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"OK"]];
    closeButton.momentary = YES;
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
    closeButton.tintColor = [UIColor blackColor];
    [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];

    [actionSheet addSubview:closeButton];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

【问题讨论】:

    标签: ios uipickerview uiactionsheet


    【解决方案1】:

    终于解决了

    首先我必须设置选择器视图的宽度,就像我提到的那样

    CGRect pickerFrame=CGRectMake(0, 40, 0, 0);
    

    所以它可以像

    CGRect pickerFrame=CGRectMake(0, 40, 320, 0);
    

    我找到了一个更好的解决方案:

    只需通过单击文本字段来调用操作表中的选择器视图:

    self.textField.inputView = yourCustomView;
    

    【讨论】:

    • 我用了第三个选项,太棒了!
    猜你喜欢
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多