【发布时间】:2009-12-11 21:20:57
【问题描述】:
我想要什么:
顶部带有 UISearchBar 的 UIView。开始编辑 searchBar 会使当前视图变暗并显示来自另一个 [UITableView]Controller 的搜索结果。
我的尝试:
在界面生成器中:
- 向 UIView 添加“搜索栏和搜索显示控制器”。
- 为我的 UITableViewController 添加一个占位符对象
- 添加一个 UITableView 对象并将其设置为 UITableViewController 的视图
- 将 UISearchBar 的委托设置为 UITableViewController
- 将 UISearchDisplayController 上的所有 outlet 设置为 UITableViewController
在代码中:
- 将 UISearchBarDelegate、UISearchDisplayDelegate 协议添加到 UITableViewController
我得到了什么:
点击编辑搜索字段会使应用程序崩溃。没有错误消息,只有 UITableViewController 中的“viewDidLoad”方法被调用。
结论:
如何为 UIView 中的 UISearchBar 使用外部控制器?
【问题讨论】:
-
"点击编辑搜索字段会使应用程序崩溃。"您应该能够调试应用程序崩溃的位置。在调试模式下运行时,堆栈跟踪是什么?
标签: iphone uisearchbar uisearchdisplaycontroller