【问题标题】:Code not working when typing in UITextField the button not visible?在 UITextField 中键入按钮不可见时代码不起作用?
【发布时间】:2016-11-25 23:05:43
【问题描述】:

这是我在 textField 中输入任何内容的方法,但标题按钮在标题中不可见。

- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

    NSUInteger finalLenght = textField.text.length - range.length + string.length;
    //SearchBtn.hidden = (finalLenght == 0);

    if (finalLenght==0) {
        self.navigationItem.rightBarButtonItem = nil;
    }else{
        UIButton *SearchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [SearchBtn setTitle:CustomLocalizedString(@"FIND CVS") forState:UIControlStateNormal];
        [SearchBtn addTarget:self action:@selector(actionFindJobs:) forControlEvents:UIControlEventTouchUpInside];
        SearchBtn.frame = CGRectMake(0, 0, 80, 30);
        SearchBtn.hidden = YES;
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:SearchBtn];
    }
    return YES;
}

【问题讨论】:

  • 当我单击 UITextField 并在 UITextField 中输入任何内容时,此方法不会调用,所以我不明白的原因是什么?
  • 你设置了 textField.delegate = self; ?
  • 是的,这是委托问题,我已经解决了这个问题的朋友

标签: ios objective-c iphone ios7


【解决方案1】:

如何改变这个:

SearchBtn.hidden = YES;

到:

SearchBtn.hidden = NO;

【讨论】:

    【解决方案2】:

    请检查以下代码

    [SearchBtn setEnabled:YES];
    

    [SearchBtn setEnabled:NO];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-08
      • 2018-05-29
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多