2013-09-30 56 views
5

在iOS7之前,我們通過將UITableViewIndexSearch添加到部分索引標題,在UITableView索引的頂部添加了放大鏡圖標。UITableView部分索引無法滾動到搜索欄索引

通過拖動到在部分索引的放大鏡圖標,所述的tableView可以滾動到用下面的代碼搜索欄:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 

    NSInteger resultIndex = [self getSectionForSectionIndex:index]; 

    // if magnifying glass 
    if (resultIndex == NSNotFound) { 
     [tableView setContentOffset:CGPointZero animated:NO]; 
     return NSNotFound; 
    } 
    else { 
     return resultIndex; 
    } 
} 

然而在IOS 7,這將僅滾動到所述第一部分,而不是搜索欄。

回答

9

爲了解決這個問題,我們調整了內容偏移,以考慮的iOS 7推出的UITableView的內容插圖:CGPointMake(0.0, -tableView.contentInset.top)

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { 

    NSInteger resultIndex = [self getSectionForSectionIndex:index]; 

    // if magnifying glass 
    if (resultIndex == NSNotFound) { 
     [tableView setContentOffset:CGPointMake(0.0, -tableView.contentInset.top)]; 
     return NSNotFound; 
    } 
    else { 
     return resultIndex; 
    } 
}