使用 UIPickerView 初始化 UIButton 并将其放置在 UIActionSheet 中

发布于 2024-12-28 13:37:42 字数 1603 浏览 1 评论 0原文

我正在通过 添加 UIPickerView & 来实现选择器操作表中的按钮 - 如何?。我尝试用 UIButton 替换 UISegmentedControl 但它不起作用。有人能提醒我为什么 UIButton 不能在这里显示吗?

谢谢。

- (IBAction) makeButtonPressed: (id) sender;
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
    [actionSheet setTitle:@"Select Make"];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque];

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
    pickerView.dataSource = self;
    pickerView.delegate = self;
    pickerView.showsSelectionIndicator = YES;
    [actionSheet addSubview:pickerView];

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

    UIButton *doneButton = [[UIButton alloc] init];
    doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:doneButton];

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];

    [actionSheet setBounds:CGRectMake(0, 0, 320, 460)];
}

I am implementing picker by Add UIPickerView & a Button in Action sheet - How?. I tried to replace the UISegmentedControl with a UIButton but it does not working. Could someone remind me why UIButton cannot be shown here?

Thank you.

- (IBAction) makeButtonPressed: (id) sender;
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
    [actionSheet setTitle:@"Select Make"];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque];

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
    pickerView.dataSource = self;
    pickerView.delegate = self;
    pickerView.showsSelectionIndicator = YES;
    [actionSheet addSubview:pickerView];

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

    UIButton *doneButton = [[UIButton alloc] init];
    doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
    [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
    [actionSheet addSubview:doneButton];

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];

    [actionSheet setBounds:CGRectMake(0, 0, 320, 460)];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2025-01-04 13:37:42

UIButton 的指定初始值设定项是 +buttonWithType:。您应该使用预定义样式之一创建按钮,或使用UIButtonTypeCustom

UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundRect];
doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
[doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:doneButton];

The designated initializer for UIButton is +buttonWithType:. You should create your button with one of the predefined styles, or use UIButtonTypeCustom.

UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundRect];
doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
[doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:doneButton];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文