1
我正在使用以下代碼來顯示TableView的索引。 我的問題是,按下放大鏡圖標,不會將我帶到搜索欄所在的表格頂部。索引的每個其他部分都起作用。按下UiTableView索引上的放大鏡圖標
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
if (tableView == [[self searchDisplayController] searchResultsTableView])
return nil;
else {
//I add the magnifying glass to the index
NSArray *indexArray = [NSArray arrayWithObject:UITableViewIndexSearch];
// I return the array for the index after I add the rest of Index items
return [indexArray arrayByAddingObjectsFromArray:self.sectionsarray];
}
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
// I set index - 1 so I can compensate for the addition of the magnifying glass
return index -1;
}
什麼是你的代碼嗎? – 2012-03-23 15:46:42
由於您沒有'-1'索引部分,選擇索引爲0(玻璃圖標)的標題不會執行您想要的操作。相反,您必須手動處理這種情況,並將滾動視圖內容滾動到您有搜索欄的左上角。這是'sectionForSectionIndexTitle'方法的內容。 – 2012-03-23 17:17:05
很好的解決方案。我選擇了使用動畫:NO,因爲這給了像聯繫人應用程序的結果。同樣,因爲我沒有搜索欄上的IBOutlet,只要x = y = 0,任意大小的矩形也可以。 – Ants 2012-06-30 01:52:50