问题描述
- KVO观察者模式不可以这么用吗
-
- (void)viewDidLoad
{
[super viewDidLoad];
[self dataArray];
[self createNav];
[self createTableView];
[self createsearchBar];[_searchBar addObserver:self forKeyPath:@"text" options:NSKeyValueObservingOptionNew context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
NSLog(@"%@%@%@",keyPath,change,context);
if (_searchBar.text.length==0) {
NSLog(@"!!!!!!");
_searchBar=nil;
[_tableView reloadData];
}
NSLog(@"----");
}
- (void)viewDidLoad
时间: 2024-10-30 01:35:53