<legend id='4iNw1'><style id='4iNw1'><dir id='4iNw1'><q id='4iNw1'></q></dir></style></legend><tfoot id='4iNw1'></tfoot>

  • <small id='4iNw1'></small><noframes id='4iNw1'>

      <bdo id='4iNw1'></bdo><ul id='4iNw1'></ul>

      1. <i id='4iNw1'><tr id='4iNw1'><dt id='4iNw1'><q id='4iNw1'><span id='4iNw1'><b id='4iNw1'><form id='4iNw1'><ins id='4iNw1'></ins><ul id='4iNw1'></ul><sub id='4iNw1'></sub></form><legend id='4iNw1'></legend><bdo id='4iNw1'><pre id='4iNw1'><center id='4iNw1'></center></pre></bdo></b><th id='4iNw1'></th></span></q></dt></tr></i><div id='4iNw1'><tfoot id='4iNw1'></tfoot><dl id='4iNw1'><fieldset id='4iNw1'></fieldset></dl></div>

        UITextField rightView "WhileEditing";问题

        时间:2023-07-07
        • <bdo id='PbqEo'></bdo><ul id='PbqEo'></ul>

              • <i id='PbqEo'><tr id='PbqEo'><dt id='PbqEo'><q id='PbqEo'><span id='PbqEo'><b id='PbqEo'><form id='PbqEo'><ins id='PbqEo'></ins><ul id='PbqEo'></ul><sub id='PbqEo'></sub></form><legend id='PbqEo'></legend><bdo id='PbqEo'><pre id='PbqEo'><center id='PbqEo'></center></pre></bdo></b><th id='PbqEo'></th></span></q></dt></tr></i><div id='PbqEo'><tfoot id='PbqEo'></tfoot><dl id='PbqEo'><fieldset id='PbqEo'></fieldset></dl></div>

                    <tbody id='PbqEo'></tbody>
                1. <tfoot id='PbqEo'></tfoot>

                  <small id='PbqEo'></small><noframes id='PbqEo'>

                  <legend id='PbqEo'><style id='PbqEo'><dir id='PbqEo'><q id='PbqEo'></q></dir></style></legend>
                2. 本文介绍了UITextField rightView "WhileEditing";问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试将 UITextField 子类化如下,以将自定义 rightView 实现为清除按钮:

                  I try to subclass UITextField as follows to implement custom rightView as a Clear button:

                  -(void) drawRect:(CGRect)rect
                  {
                  
                      [self.layer setBackgroundColor:[[UIColor colorWithRed:20.0/255.0 green:20.0/255.0 blue:20.0/255.0 alpha:1] CGColor]];
                      [self.layer setCornerRadius:15.0];
                  
                      UIImage  *imgClear = [UIImage imageNamed:@"btnClear"];
                      CGSize iSize = [imgClear size];
                  
                      UIButton *clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, iSize.width, iSize.height)];
                  
                      [clearButton setImage:imgClear forState:UIControlStateNormal];
                      [clearButton addTarget:self action:@selector(clearText:) forControlEvents:UIControlEventTouchUpInside];
                  
                      [self setRightViewMode:UITextFieldViewModeWhileEditing];
                      [self setRightView:clearButton];
                  
                      [clearButton release];
                  }
                  

                  但问题是:当文本字段刚刚成为焦点时,清除"按钮也变得可见,并且在我开始点击键盘后它消失了.有什么想法吗?

                  but the Problem is: when the textfield just becomes focus, "clear"-button becomes visible too and after i begin to tap the keyboard it dissapears. Any ideas?

                  推荐答案

                  我也遇到了同样的问题.我想这是一个 iOS 错误,但是,我尝试通过以下实现来解决这个问题,它对我来说很好.希望这会对你有所帮助.

                  I meet the same problem, too. I guess this is an iOS bug, however, I tried to fix this problem by following implementations and it works fine for me. Hope this will help you.

                  - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
                      ...
                      [self addTarget:self action:@selector(onEditing:) forControlEvents: UIControlEventEditingChanged]
                      ...
                  }
                  
                  -(void) onEditing:(id)sender {
                      if(![self.text isEqualToString:@""]){
                          self.rightViewMode = UITextFieldViewModeAlways;
                      }else{
                          self.rightViewMode = UITextFieldViewModeNever;
                      }
                  }
                  - (BOOL)becomeFirstResponder{
                      BOOL ret = YES ;
                      ret = [super becomeFirstResponder] ;
                      if( ret & ![self.text isEqualToString:@""]){
                          self.rightViewMode = UITextFieldViewModeAlways;
                      }else{
                          self.rightViewMode = UITextFieldViewModeNever;
                      }
                  
                      return ret ;
                  }
                  - (BOOL)resignFirstResponder
                  {
                      BOOL ret = YES ;
                      ret = [super resignFirstResponder] ;
                      if( ret )
                          self.rightViewMode = UITextFieldViewModeNever;
                      return ret ;
                  }
                  - (void) clearText:(id)sender
                  {
                      self.text = @"";
                      self.rightViewMode = UITextFieldViewModeNever;
                  }
                  

                  这篇关于UITextField rightView "WhileEditing";问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIBarButtonItem 与 UIButton 作为 CustomView - 从 UIButton,如何访问它的 下一篇:在文本 Swift 末尾显示更多按钮

                  相关文章

                  1. <i id='BYAw9'><tr id='BYAw9'><dt id='BYAw9'><q id='BYAw9'><span id='BYAw9'><b id='BYAw9'><form id='BYAw9'><ins id='BYAw9'></ins><ul id='BYAw9'></ul><sub id='BYAw9'></sub></form><legend id='BYAw9'></legend><bdo id='BYAw9'><pre id='BYAw9'><center id='BYAw9'></center></pre></bdo></b><th id='BYAw9'></th></span></q></dt></tr></i><div id='BYAw9'><tfoot id='BYAw9'></tfoot><dl id='BYAw9'><fieldset id='BYAw9'></fieldset></dl></div>
                    • <bdo id='BYAw9'></bdo><ul id='BYAw9'></ul>
                    <legend id='BYAw9'><style id='BYAw9'><dir id='BYAw9'><q id='BYAw9'></q></dir></style></legend>

                    1. <tfoot id='BYAw9'></tfoot>
                    2. <small id='BYAw9'></small><noframes id='BYAw9'>