【发布时间】: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