ios - 如何以编程方式在自定义表格 View 中附加搜索栏

标签 ios xcode uitableview

我已经使用自定义表格 View 单元格实现了表格 View 。 我想将搜索栏放在表格 View 中。

有人可以告诉我如何以编程方式附加一个这样的搜索栏。 请尽量不要提供外部链接。谢谢。

最佳答案

UISearchBar *tempSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0)];
self.searchBar = tempSearchBar;
[tempSearchBar release];
self.searchBar.delegate = self; 
[self.searchBar sizeToFit];  
self.tableView.tableHeaderView = self.searchBar; 

希望这有帮助。

关于ios - 如何以编程方式在自定义表格 View 中附加搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14682854/

相关文章:

ios - 检测 iOS 中的旋转变化

ios - UIbutton不响应触摸事件

xcode - 如何在Xcode 9.3上将“快速打开”还原为黑暗主题?

ios - 工具栏中的栏按钮方法未调用

uitableview - [UITableViewCell _didChangeToFirstResponder :]: message sent to deallocated instance

swift - 表格 View 单元格在滚动 Swift 时改变颜色

ios - 图像图标未显示在 swift 文本框的右侧

ios - 通过兄弟 subview 传播触摸事件?

iOS 打印机模拟器错误 - Air Print

ios - 核心图 : Label in BarChart