Iphone uinavigationcontroller内部的UISearchbar

Iphone uinavigationcontroller内部的UISearchbar,iphone,Iphone,看起来是个愚蠢的问题,但是…: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 20.0, self.navigationController.view.bounds.size.width, HEADER_HEIGHT)]; mySearchDisplayControlle

看起来是个愚蠢的问题,但是…:

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated]; 
self.bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 20.0, self.navigationController.view.bounds.size.width, HEADER_HEIGHT)];
mySearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:bar contentsController:self];
mySearchDisplayController.delegate = self;
mySearchDisplayController.searchResultsDataSource = self;
mySearchDisplayController.searchResultsDelegate = self;
[self.navigationController.view addSubview:self.bar];
当我不按取消或隐藏tableview时,所有行为都正常工作。 之后,搜索栏被关闭,我看到一个清晰的导航栏,没有搜索栏。 我已更改为viewDidload,但没有更改

开始打印前:

之后:


尝试将搜索栏添加为导航栏的标题视图。这可能有用

请参阅本网站:


它可能会帮助您尝试将搜索栏添加为导航栏的标题视图。这可能有用

请参阅本网站:


它可能会帮助你

你能详细说明你看到的行为吗<代码>视图将出现实际上不适合这种代码
viewDidLoad
更合适。您能详细说明您看到的行为吗<代码>视图将出现实际上不适合这种代码
viewDidLoad
更合适。它正在工作,[[self.navigationController.navigationBar topItem]setTitleView:self.bar];但当我尝试在搜索栏中写东西时,搜索栏会上升并关闭,就像searchcontroller认为搜索栏放在表格中,而不是在导航栏中一样。你能把你的代码放在搜索栏的快照中吗(搜索栏上升并关闭)。我能看到哪里出了问题..tnx,请看这里,无需添加任何代码,只需清除委托函数;它正在工作,[[self.navigationController.navigationBar topItem]setTitleView:self.bar];但当我尝试在搜索栏中写东西时,搜索栏会上升并关闭,就像searchcontroller认为搜索栏放在表格中,而不是在导航栏中一样。你能把你的代码放在搜索栏的快照中吗(搜索栏上升并关闭)。我能看到哪里出了问题..tnx,请看这里,无需添加任何代码,只需清除委托函数;