XCode: Displaying a UIDatePicker when user clicks on UITextbox

前端 未结 4 1438
一个人的身影
一个人的身影 2020-12-29 00:32

I have already researched this topic to death and found people posting the exact same question on a number of websites including right here in stackoverflow.

I have

4条回答
  •  清歌不尽
    2020-12-29 01:14

    add UITextField's delegate in .h file to call this function when touched. then use the text field's tag value to determine what you want to do when the field is selected.

    -(BOOL) textFieldShouldBeginEditing:(UITextField *) textField 
    {
        activeTextField = textField;
    
        if (textField.tag == 1) 
        {
            self.datePicker.datePickerMode = UIDatePickerModeDate;
            self.isDatePicker = TRUE;
            self.tempTextField = textField;
            [self showPicker];
            return NO;
        }
        else if (textField.tag == 2) 
        {
            self.datePicker.datePickerMode = UIDatePickerModeTime;
            self.isDatePicker = TRUE;
            self.tempTextField = textField;
            [self showPicker];
    
            return NO;
        }
        else if (textField.tag == 3)
        {
            self.isDatePicker = FALSE;
            self.tempTextField = textField;
            [self showPicker];
            return NO;
        }
        else
        {
            self.tempTextField = textField;
            return YES;
        }
    }
    

提交回复
热议问题