objective-c - iOS监听isFirstResponder的变化
天蓬老师
天蓬老师 2017-04-28 09:05:33
0
2
703

我想监听一个UISearchBar的isFirstResponder的值的变化,采用了如下代码:


[_searchBar addObserver:self forKeyPath:@"_isFirstResponder" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    NSLog(@"test");
    return ;
}

在UISearchBar的delegate方法中可以看到isFirstResponder确定已经改变了,但是却没有输出"test",用searchBar.observationInfo也可以看到该监听器确实是已经添加成功了,请问谁有没有碰到过这种情况?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
習慣沉默

There is no such key as "_isFirstResponder"! You can judge it by valueForKey or valueForKeyPath! If you want to monitor this property, you can customize UISearchBar, override the becomeFirstResponder and resignFirstResponder methods, and use Notification or delegate or block to pass the message

PHPzhong

It is recommended to learn about RAC. This can be easily solved with RAC.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!