简体   繁体   English

如何在UITableview标题内的UISearchBar中添加按钮?

[英]How do you add a button to a UISearchBar within UITableview's header?

My question is different than how to add button to UISearchBar , as he is adding the searchbar in a navigation bar and I need to use a table view for the same. 我的问题与如何向UISearchBar添加按钮不同,因为他在导航栏中添加了搜索栏,因此我需要使用表格视图。

I am working in an app in which I need to add a button beside the search box in UISearchbar. 我在一个应用程序中工作,需要在UISearchbar的搜索框旁边添加一个按钮。 I tried to find a solution for this but the only way I've found is using UINavigationBar. 我试图为此找到解决方案,但我发现的唯一方法是使用UINavigationBar。 However, I need to animate the searchbar on begin and end of an editing event, so putting it on a navigation bar doesn't meet my needs. 但是,我需要在编辑事件的开始和结束时对搜索栏进行动画处理,因此将其放在导航栏上无法满足我的需求。

I have put my search bar in my UITableview's header view so that it can scroll with the table view. 我已将搜索栏放在UITableview的标题视图中,以便它可以与表视图一起滚动。 It works fine and animates as expected and of course scrolls, except for the button beside the search box. 除了搜索框旁边的按钮之外,它可以正常工作并可以按预期进行动画处理,当然也可以滚动。

Is there any other way to add a button beside the search box in UISearchBar? 还有其他方法可以在UISearchBar的搜索框旁边添加按钮吗?

Yes you can add them both on a view and return the view in 是的,您可以将它们都添加到视图中并在

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

method. 方法。

IB should work as well. IB也应该工作。 Just make sure to connect the UISearchbar delegate to the View Controller and use its delegate methods from the VC, or alternatively use IBactions called from your searchBar to pass your data and actions to the VC logic. 只需确保将UISearchbar委托连接到View Controller并使用其在VC中的委托方法,或者使用从searchBar调用的IBactions即可将您的数据和动作传递给VC逻辑。 Nelson 纳尔逊

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM