开发者

displaying datepicker on the tap of a particular text field only

i have a number of textfields . i want to display datepicker on the tap of a particular textfield on开发者_如何学编程ly. wat i have is a number of textfields for entering details of a person like Name, address, date of birth etc... On the tap of text field for entering the date of birth i want to display date picker. if i include the code for the date picker in the textFieldShouldBeginEditing method ,will that show datepicker for tap on every textfield, .

Pls help me out to find a solution for this ,, I am new to iphone app development...


If you have your UITextField as an attribute of the class simply check it on the delegate method

- (BOOL) textFieldShouldBeginEditing: (UITextField*) textField {
      if (textField == _datePickerField) {
        // Show picker
      }
}

If not, UITextField is a subclass of UIView. You can tag it when created with the value of an enumeration and then, on the delegate method check the tag. If the textField you are editing is the one who raises the DatePicker, do it.

enum {
  iee_Field1 = 0,
  iee_Field2,
  iee_DatePcikerField
};

- (BOOL) textFieldShouldBeginEditing: (UITextField*) textField {
  if (textField.tag == iee_DatePickerField) {
    // Show picker
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜