2010-07-02 69 views
1

我試圖在UITableView內執行UISearchBar,其行爲與iPod應用程序的「藝術家」選項卡中的行爲相同。UITableView -reloadSectionIndex標題未調用數據源

我有隱藏導航欄,並調整搜索框的大小以顯示「取消」按鈕等,但無法讓它隱藏部分索引標題。

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar 
{ 
    inSearchMode_ = YES; // tell sectionIndexTitlesForTableView: to return nil 
    tableView_.scrollEnabled = NO; // works correctly, var is definitely wired 
    [tableView_ reloadSectionIndexTitles]; // doesn't call sectionIndexTitlesForTableView: 
    ... 

我錯過了什麼嗎?是UITableView -reloadSectionIndexTitles壞了?

通常我對這種事情的迴應是打電話給reloadData,但是這有副作用導致UISearchBar失去焦點。

回答

0

看來我需要做的是使用UISearchDisplayController,而不是手卷我自己。我能夠修改「TableSearch」示例以使用章節和章節標題,並且它的行爲符合我的要求。

1

我想你想的辦法是沿着這些線路(說你有你想搜索一個ArtistController):

  • 子控制器添加到所謂ArtistSearchController的ArtistController
  • 當搜索框被點擊,將ArtistSearchController作爲模式(隱藏藝術家),或者如果您仍然想要在後臺顯示藝術家,請添加透明度。
  • 當輸入搜索詞時,爲ArtistSearchController創建一個模型,這是ArtistController的數據,使用搜索詞進行過濾,然後在列表視圖中顯示
  • 當用戶點擊取消時關閉模式視圖。

這將節省您從您操縱原來的控制器/導航欄,並給它更好的可用性

+0

這聽起來很像UISearchDisplayController的運行方式,現在我已經玩過樣本了。 – chrisbtoo 2010-07-02 17:40:50