XCode:如何在代码中直接用内容填充UIPickerView?
我该怎么做?我想用欧元、美元、英镑等值填充它,并在点击相应行时将值粘贴到文本字段中。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Make a new view, or do what you want here
UIPickerView *picker = [[UIPickerView alloc]
initWithFrame:CGRectMake(0, 244, 320, 270)];
[self.view addSubview:picker];
return NO;
}
How do I do that? i want to fill it with values like EURO, USD, POUND and so on and paste the value into a textfield when i tap on the corresponding row.
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Make a new view, or do what you want here
UIPickerView *picker = [[UIPickerView alloc]
initWithFrame:CGRectMake(0, 244, 320, 270)];
[self.view addSubview:picker];
return NO;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该在委托方法
-(NSString*) pickerView:(UIPickerView*)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
中实现,该方法将返回标题@"EURO"< /code>,
@"USD"
,@"POUND"
,@"RUB"
为您的行。例如,
You should implement in your delegate method
-(NSString*) pickerView:(UIPickerView*)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
that will return titles@"EURO"
,@"USD"
,@"POUND"
,@"RUB"
for your rows.For example,
在您的委托方法中编写代码
{
返回字符串;
在数组
中添加这样的@“一”,@“二”,@“三”,@“四”
write code in your delegate method
{
return string;
}
In Array add like this @"one", @"two", @"three", @"four"
正如其他人已经写的那样,您必须添加上面提到的委托方法,以使用数组中的项目填充 PickerView。要将值写入文本字段,您可以通过两种方式执行此操作。您可以编写一个 pickerView didSelectRow: 委托方法,如下所示:
每次您点击一行时,这都会更新文本字段。另一种方法是在按下按钮或执行其他操作时拉取 pickerView 的值。类似于
As others have already written you have to add the above mentiond delegate method to fill up your PickerView with items from an array. For writing the value into a textfield, you can do this in 2 ways. You can either do write a pickerView didSelectRow: delegate method like this:
This will update the textField each time you tap on a row. The other way is that you pull the value of the pickerView on a button press or on some other action. Similar to