這是我在textField中輸入任何內容的方法,但標題按鈕在標題中不可見。在UITextField中輸入時,代碼不起作用該按鈕不可見?
- (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; ? – Hussein
是的,這是代表問題,我已經解決了這個問題的朋友 –