我正在努力做到这一点:
Consider a table view with Search Bar on its header.Table view gets refreshed whenever string is searched.
我有 2 节课
TableView Controller (UIViewController 子类)
包含 UITableView - 显示其表
header view of the table is loaded from the Header class(UIToolBar subclass)
.
标题 (UITableView 的标题)
-包含 UISearchBar 及其委托(delegate)
这
UISearchBarDelegates call back a function in TableViewController
那叫
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
导致App崩溃
函数调用栈帧如下
[UITableView reloadSections:withRowAnimation:]
[TableViewController functionThatCallsReloadSection]
[Header searchBarSearchButtonClicked:]
reloadSection 导致应用程序崩溃。任何想法为什么会这样?
Is it because the delegate function is still active on the stack while the the table view header is reloaded??
我没有更改与表格 View 相关的任何内容(行数或节数没有变化)。我要做的只是重新加载表格 View 。
编辑:
我正在尝试在 iPad 中做所有这些事情,它在使用我不想使用的 UISearchDisplayController 时提供了一个弹出窗口。我已经有一个表格 View ,一旦输入文本并点击搜索按钮,我想刷新它,使用搜索代表。
唯一的问题是,一旦我在 UISearchBar 的搜索委托(delegate)中调用 [UITableView reloadSection:](UISearchBar 位于我要重新加载的 UITableView 的标题上),应用程序就会崩溃。
最佳答案
我能够通过使用 tableViewHeader 而不是使用 table view header 委托(delegate)方法加载 table view header 来解决问题,其中我使用了一个初始化为 table view header 的指针。
关于uisearchbar - 不能将 UISearchBar 放在 UITableView 标题中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9673303/