开发者

UITableView with Right-Side Index, Sections and Searchbar Causes Right-Side Index to Become Squished

I have a UITableView with a section, searchbar and a right-hand side index. Initially, everything works and is drawn properly. However, when I type into my search bar then click cancel the right index is not redrawn properly. Here's how the index looks after I click the Cancel button.

UITableView with Right-Side Index, Sections and Searchbar Causes Right-Side Index to Become Squished

Here's normal:

UITableView with Right-Side Index, Sections and Searchbar Causes Right-Side Index to Become Squished

[Update]

For some reason I needed to use this method to get my table reloadData to work:

-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { ...}

instead of this method:

-(void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller { ...}

Here is 开发者_运维知识库my method:

/* Reset Table here
 */
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
    NSLog(@"\n===searchBarTextDidEndEditing");
    self.isFiltered = NO;
    self.tableView = self.myTableView;

    [self genIndexWithFilter:NO];
    [self.tableView reloadData];

}

If someone can explain the subtle details, I'll upvote and accept their answer.


Assuming your self.isFiltered boolean is the variable which controls which set of data is being rendered to screen; either the full list or a refined searched set.

When -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { ...} is invoked, the self.isFiltered flag is set and you reload the table via. [self.tableView reloadData]; reloads the table checking the if you are rendering the filtered data or not.

As well when reloadData is called it checks to see how many section are to be rendered. If done correctly, you can have something like this...

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    if(self.isFiltered) //If searching
        return nil; //Return empty section
    else
        return sectionSelectionArray; //Return list of headers
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜