将UIPicker添加到文本字段 [英] Adding UIPicker to textfield

查看:50
本文介绍了将UIPicker添加到文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格视图&我必须在某些单元格中显示文本字段.当用户单击文本字段时,我希望选择器视图以0到99之间的整数值显示.一旦用户在选择器视图中选择了项目,则需要在该特定文本字段上显示相同的内容.任何帮助将由衷的感谢.

I have a table view & I have to display text fields in some cells. When user click on the text field, I want the picker view to be displayed with integer values from 0 to 99. once the user selects the item in picker view the same needs to be displayed on that particular text field. Any help would be sincerely appreciated.

推荐答案

   -(void) viewDidLoad
 {
arrayNo = [[NSMutableArray alloc] init];
[arrayNo addObject:@"1"];
[arrayNo addObject:@"2"];
[arrayNo addObject:@"3"];
// and so on....
  }

将此行的目标添加到ur文本字段功能

Add target of this line to ur textfield function

  UITextfield *entered2;
  //..... some codes
   [entered2 addTarget:self action:@selector(showPicker)forControlEvents:UIControlEventEditingDidBegin];
[myview addSubview:entered2];




  -(void) showPicker
  {
[entered2 resignFirstResponder];
    pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,240,220,0)];

pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;    

[self.view addSubview:pickerView];  
[pickerView release]; 
 }

 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
   {
    return [arrayNo count];
   }
  - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
 return 1;  
   }
   - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
   {
entered2.text=[arrayNo objectAtIndex:row];
[pickerView removeFromSuperview];
   }
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
   {
return [arrayNo objectAtIndex:row];
[pickerView removeFromSuperview];
   }
   - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 300;
return sectionWidth;
     }

这篇关于将UIPicker添加到文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆