小编clo*_*sen的帖子

我是否必须手动删除KVO中的Observer

我读过有关KVO 的苹果文件,它说:

注意:键值观察addObserver:forKeyPath:options:context:方法不保持对观察对象,观察对象或上下文的强引用.您应该确保在必要时保持对观察,观察对象和上下文的强引用.

观察者对象没有对观察对象的强引用.

这个男人我不能打电话给removeObserver:forKeyPath:这个dealloc方法吗?可以自动删除观察者吗?

objective-c key-value-observing ios

4
推荐指数
1
解决办法
6294
查看次数

为什么我的UISearchBar的框架被UISearchDisplayController更改

我在我的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

3
推荐指数
2
解决办法
6737
查看次数