-2

How can I add multiple UIPickerViews and textfields inside UITableview , and use the different methods for managing UIPickerViews?

dlemstra
  • 6,870
  • 2
  • 24
  • 41
Safae Xd
  • 5
  • 1
  • What did you mean by multiple pickerView? Did you mean to show pickerView when textField is selected or just Picker View added to TableView. A diagram of what you are trying to achieve would be nice. – Anupdas May 12 '13 at 20:55
  • thabk you for reply , I want to show pickerView when textField is selected .I am new in ios developement I didn't found how to do that – Safae Xd May 12 '13 at 21:03
  • Do you want to add UIDatePicker or UIPickerView? – Anupdas May 12 '13 at 21:20

1 Answers1

1

If you need to show pickerView when textField is selected you need to add the pickerView as inputView to the textField.

If you have many textFields, it would be better to add it when the editing starts for a textField. To identify which textField should be shown picker give tag to each textField.

- (void)textFieldDidBeginEditing:(UITextField *)textField{

   NSInteger tag = textField.tag;

   //Conditionally check which textField you want to show picker
   //Then call the method to add inputView to textField
   [self addInputViewToTextField:textField];

}

- (void)addInputViewToTextField:(UITextField *)textField{

    //Initialize pickerView 
    UIDatePicker *datePicker = ...

    textField.inputView = datePicker;

}

A sample project to show UIDatePicker when textField is selected.

Anupdas
  • 10,058
  • 2
  • 33
  • 59
  • I have to add both uidatepicker and uipickerview , but the textfield selected should be included into a tableview – Safae Xd May 12 '13 at 21:25
  • You need to make a subclass of UITableViewCell with textField added to it. Are you using storyboard or XIB? Have a look at this [answer](http://stackoverflow.com/a/2230596/767730), explains how to add textField to UITableView. If you are using pickerView make sure to use a dataSource (array or dictionary) for it, based on the textField selected change the dataSource values and reload the pickerView. I would give you pointers. It would be better if do it step by step. – Anupdas May 12 '13 at 21:31