键入UITextField时代码不起作用按钮不可见?

时间:2016-07-22 06:37:55

标签: ios objective-c iphone ios7

这是我在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;
}

2 个答案:

答案 0 :(得分:0)

如何改变这个:

SearchBtn.hidden = YES;

为:

SearchBtn.hidden = NO;

答案 1 :(得分:0)

请查看以下代码

[SearchBtn setEnabled:YES];

[SearchBtn setEnabled:NO];