我有一个拥有焦点的UITextfield,光标就在那里。如果用户按下一个按钮,而UITextfield为空,我就会启动一个UIAlertView。当用户按下OK时,UITextField仍具有焦点,但光标消失。
问题仅出现在iOS7上,而不出现在iOS6上。
我该如何修复这个bug呢?
编辑以获取更多信息:
UITextField是第一个响应器,这不是问题,当我输入时,它可以工作,但没有光标...
发布于 2013-11-29 16:17:33
您应该在警报视图委托中将文本字段设置为first responder。
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {   
 [myTextField becomefirstresponder];}谢谢
发布于 2013-11-29 16:20:23
在.h文件中添加文本字段的委托
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        //u need to change 0 to other value(,1,2,3) if u have more buttons.then u can check which button was pressed.
    if (buttonIndex == 0) {  //0 for Ok button index
      [self textFieldDidBeginEditing:yourTextFeild];
    }
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    UITextPosition *beginning = [textField beginningOfDocument];
    [textField setSelectedTextRange:[textField textRangeFromPosition:beginning
                                                          toPosition:beginning]];
}发布于 2013-11-29 17:13:11
我在ios 7中也发现了同样的问题。我仍然不知道原因,但也许您应该设置textfield的tintcolor属性。
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
    [[UITextField appearance] setTintColor:[UIColor blueColor]];
}https://stackoverflow.com/questions/20280929
复制相似问题