我读过有关KVO 的苹果文件,它说:
注意:键值观察addObserver:forKeyPath:options:context:方法不保持对观察对象,观察对象或上下文的强引用.您应该确保在必要时保持对观察,观察对象和上下文的强引用.
观察者对象没有对观察对象的强引用.
这个男人我不能打电话给removeObserver:forKeyPath:这个dealloc方法吗?可以自动删除观察者吗?
我在我的TopBar.m中写UISearchBar是这样的:
_tempSearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(44, 0, 320 - 44, 43)];
_tempSearchBar.barStyle=UIBarStyleDefault;
_tempSearchBar.placeholder=@"??";
[self addSubview:_tempSearchBar];
Run Code Online (Sandbox Code Playgroud)
结果是这样,是对的.

然后我在另一个类中编写UISearchDisplayController,如下所示:
_topBar.tempSearchBar.delegate = self;
_searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_topBar.tempSearchBar contentsController:self];
[_searchDisplayController setDelegate:self];
[_searchDisplayController setSearchResultsDataSource:self];
Run Code Online (Sandbox Code Playgroud)
UISearchBarDelegate是这样的:
#pragma mark -
#pragma mark UISearchBarDelegate
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[_searchDisplayController setActive:YES animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
当我单击UISearchBar时,它显示如下,searchBar的框架被更改.为什么?

当我取消UISearchDisplayController时,它是这样的:

为什么框架改变了?UISearchDisplayController的宽度从320-44变为320?
谢谢.
uisearchbar uisearchdisplaycontroller uisearchbardelegate uisearchbardisplaycontrol ios