我有一個表視圖&我必須在某些單元格中顯示文本字段。當用戶點擊文本字段時,我希望選擇器視圖以0到99之間的整數值顯示。一旦用戶在選擇器視圖中選擇了該項目,則需要在該特定文本字段上顯示相同的內容。任何幫助將真誠感謝。將UIPicker添加到文本框
0
A
回答
1
-(void) viewDidLoad
{
arrayNo = [[NSMutableArray alloc] init];
[arrayNo addObject:@"1"];
[arrayNo addObject:@"2"];
[arrayNo addObject:@"3"];
// and so on....
}
添加目標UR文本框功能
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;
}
0
創建一個選擇器視圖並在您的視圖控制器中實現委託和數據源方法。將選取器視圖設置爲文本字段的inputview
。當用戶編輯文本字段時,它將彈出而不是鍵盤。
使用didSelect...
委託方法可在用戶更改選取器時更新文本字段值。這條線的
0
首先在viewDidLoad方法需要實例化PickerView,並把它添加到文本框
UIPickerView *pickerView =[[UIPickerView alloc]init];
pickerView.delegate=self;
pickerView.dataSource=self;
pickerView.showsSelectionIndicator=YES;
myTextField.inputView=pickerView;
然後你必須實施UIPickerView代理
- (void)pickerView:(UIPickerView *)thePickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
myTextField.text=[arrayWithData objectAtIndex:row];
}
其中,arrayWithData是PickerView的源代碼數組。
1
夫特的iOS:(注:請改變由要求VARS名)
步驟1:聲明VARS和對象
var objPickerView : UIPickerView = UIPickerView()
// select the picker view data values
objPickerView.delegate=self;
objPickerView.dataSource=self;
objPickerView.showsSelectionIndicator=true;
// show picker view when text field clicked
self.smokingStatusText!.inputView = objPickerView
// reload the component of picker
self.objPickerView.reloadAllComponents()
// select the value of picker status(Which row must be selected)
self.objPickerView.selectRow(sStatus!, inComponent: PickerComponent.size.rawValue, animated: false)
步驟2:聲明代表和協議:
// programming mark ----- ---- ----- ----- ---- ----- ----- ---- -----
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
// programming mark ----- ---- ----- ----- ---- ----- ----- ---- -----
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
//MARK: UIPickerView Delegates
// programming mark ----- ---- ----- ----- ---- ----- ----- ---- -----
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
smokingStatusText!.text = pickerData[row]
self.smokerStatusNum = String(row)
}
// programming mark ----- ---- ----- ----- ---- ----- ----- ---- -----
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = pickerData[row]
let font:UIFont? = UIFont(name: "Georgia", size: 14.0)
let attrString = NSAttributedString(
string: titleData,
attributes: NSDictionary(
object: font!,
forKey: NSFontAttributeName))
return attrString
}
// programming mark ----- ---- ----- ----- ---- ----- ----- ---- -----
//size the components of the UIPickerView
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 36.0
}
func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return 300
}
相關問題
- 1. 將文本框添加到圖像
- 2. 將字段值添加到文本框
- 3. 將文本添加到組合框
- 4. 將大文本框添加到頁面
- 5. 將文本框添加到Gridview中
- 6. 將文本框添加到UIAlertView
- 7. python pptx將邊框添加到文本
- 8. 將css類添加到文本框javascript
- 9. 如何將文本添加到文本框?
- 10. ASP/C#,將文本添加到文本框問題
- 11. 如何將文本添加到文本框?不能代替
- 12. QT創建按鈕,將文本添加到文本編輯框
- 13. 如何將文本從文本框添加到列表中
- 14. 將文本輸入字段添加到文本框
- 15. Xcode:將文本添加到文本框中的標籤
- 16. 如何將一些文本添加到文本框
- 17. 通過javascript將文本添加到文本框中
- 18. 將文本添加到自動標籤和文本框vb.net
- 19. 將文本添加到PDF
- 20. 將文本添加到CCSprite
- 21. 將文本添加到PDF
- 22. 將文本添加到QListWidget
- 23. 將文本添加到Alternativa3d?
- 24. 將文本添加到CALayer
- 25. 如何將文本添加到文本框並將其視爲文本塊?
- 26. 將文本添加到文本(jQuery)
- 27. 添加文本框
- 28. 將文本框值添加到選項卡上的列表框
- 29. 將複選框列表中的值添加到文本框
- 30. SelectAll()將文本框添加到組框後不工作
可以你告訴我你試過了什麼? – vishy 2012-01-30 13:13:25