iPhone 为 UIPickerView 填充值

发布于 2024-10-18 03:43:54 字数 1475 浏览 3 评论 0原文

我创建了一个 UIPickerView,它在单击按钮时显示。问题是我如何填写 rowItems

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Location"
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,100,0,0)];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;
    [actionSheet addSubview:pickerView];
    [pickerView release];
    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:NSLocalizedString(@"Done", @"")]];
    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];   
    [closeButton release];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

以及单击“完成”时如何获取值。

I've created a UIPickerView, which displays on button click. The question is how I fill in the rowItems

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Location"
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,100,0,0)];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;
    [actionSheet addSubview:pickerView];
    [pickerView release];
    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:NSLocalizedString(@"Done", @"")]];
    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];   
    [closeButton release];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

and How do I get value when "done" is clicked.

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

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

发布评论

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

评论(1

记忆で 2024-10-25 03:43:54

您已经设置了警报的委托和选择器。现在你必须实施它们。您不填写选择器的数据,选择器会向您的委托人询问数据。

您需要这三个协议中定义的强制功能。

UIPickerViewDelegate
UIPickerViewDataSource
UIActionSheetDelegate

你必须实现< code>-(IBAction)dismissActionSheet:(UIButton *)sender 也是如此。

以及单击“完成”时如何获取值。

每次选择器更改时,我都会将值存储到实例变量中,一旦单击“完成”按钮,我会将其分配给我的数据模型。


编辑:如果你想学习一些东西,我会摆脱复制和粘贴解决方案并尝试自己实现它。但是YMMV。

you've set the delegate of the alert, and the picker already. Now you have to implement them. You don't fill in data for the picker, the picker asks your delegate for the data.

You need the mandatory functions defined in these three protocols.

UIPickerViewDelegate
UIPickerViewDataSource
UIActionSheetDelegate

You have to implement -(IBAction)dismissActionSheet:(UIButton *)sender too.

and How do I get value when "done" is clicked.

I would store the value to a instance variable every time the picker changes, and once the done button is clicked I would assign it to my data model.


Edit: If you want to learn something I would get rid of the copy&paste solution and try to implement it on my own. But YMMV.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文