这是我在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;
}
答案 0 :(得分:0)
如何改变这个:
SearchBtn.hidden = YES;
为:
SearchBtn.hidden = NO;
答案 1 :(得分:0)
请查看以下代码
[SearchBtn setEnabled:YES];
或
[SearchBtn setEnabled:NO];