How to programmatically select a UITextField for editing

僤鯓⒐⒋嵵緔 提交于 2019-12-11 00:36:12

问题


I have a UITextField that I need to select programmatically so when the user taps on a date in a UIDatePicker, it will be sent to that UITextField.

This is the code I have, which does not select the UITextField; I have tried all possible combinations of UIControlEvent, but none of them work. Any other ideas?

    //  set textField parameters
if([whichTextField isEqualToString:@"oStartTime"]) {
    oStartTime.backgroundColor = [UIColor colorWithRed:252.0/255.0 green:255.0/255.0 blue:197.0/255.0 alpha:1.0];
    [oStartTime sendActionsForControlEvents: UIControlEventTouchUpInside];

}
else if([whichTextField isEqualToString:@"oFinishTime"]) {
    oFinishTime.backgroundColor = [UIColor colorWithRed:252.0/255.0 green:255.0/255.0 blue:197.0/255.0 alpha:1.0];
    [oFinishTime sendActionsForControlEvents: UIControlEventTouchUpInside];
}

回答1:


See the UIResponder instance method becomeFirstResponder.



来源:https://stackoverflow.com/questions/17975680/how-to-programmatically-select-a-uitextfield-for-editing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!