7

UIPickerView迷上了输入UITextField's视图。我有它弹出。我知道用户何时选择一行。我知道该行的值。这一切都很棒。

我的问题涉及何时解雇选择器。我见过人们将带有 [Cancel] 和 [Done] 的工具栏与选择器结合使用,然后在单击任一按钮时将其关闭。这可能是最好的方法,因为用户可以退出他们的选择。

我还看到一个应用程序,用户滚动到他们想要的选择,然后再次按下它以关闭选择器。我想知道如何做到这一点。我注意到,一旦选择器通知您选择了特定行,如果用户继续单击/按下同一活动行,它将不会再次通知您。

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
4

2 回答 2

2

嘿,UserDano,因为您已将选择器作为 ipnputView 添加到您可以调用的文本字段中

 [outletForTextField resignFirstResponder] 

这将帮助您辞职 pickerView 。现在,您要执行此操作的方式是在第一次选择时要选择值,在第二次选择时(对于同一行),您要隐藏 Picker.So 保持 Bool 值来存储所选值,然后使用它来删除选择同一行时的选择器可能会起作用。希望能帮助到你

于 2011-10-11T04:14:19.803 回答
0

如果您想知道如何在单击按钮时关闭选择器视图,您可以将我在我的一个项目中使用过的这段代码片段:

    NSInteger selectedRow=[yourPickerView selectedRowInComponent:0];// i assume your picker have one component
NSString *item=[yourPickerView objectAtIndex:selectedRow];//get the selected item
yourTextField.text=[NSString stringWithFormat:@"%@",item];//display the selected item in the text field
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 480);
yourPickerView.transform=transform;
[UIView commitAnimations];//dismiss the view controller which contains the picker view

将上面的代码放在您的按钮 IBAction 方法中。希望有帮助。

于 2012-03-23T09:03:03.920 回答