【问题标题】:UITableView with Right-Side Index, Sections and Searchbar Causes Right-Side Index to Become Squished带有右侧索引、部分和搜索栏的 UITableView 导致右侧索引被压扁
【发布时间】:2011-11-24 12:08:53
【问题描述】:

我有一个带有部分、搜索栏和右侧索引的 UITableView。最初,一切正常并正确绘制。但是,当我在搜索栏中键入然后单击取消时,正确的索引未正确重绘。这是我单击“取消”按钮后索引的外观。

这是正常的:

[更新]

出于某种原因,我需要使用这种方法来让我的表 reloadData 工作:

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

代替这种方法:

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

这是我的方法:

/* 这里重置表 */ -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { NSLog(@"\n===searchBarTextDidEndEditing"); self.isFiltered = 否; self.tableView = self.myTableView; [自我 genIndexWithFilter:NO]; [self.tableView reloadData]; }

如果有人可以解释微妙的细节,我会投票并接受他们的回答。

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    假设您的self.isFiltered boolean 是控制要呈现到屏幕的数据集的变量;完整列表或精炼的搜索集。

    -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { ...} 被调用时,self.isFiltered 标志被设置并且你通过重新加载表。 [self.tableView reloadData]; 重新加载表格,检查您是否正在呈现过滤后的数据。

    reloadData 被调用时,它会检查要渲染的部分。如果操作正确,您可以拥有这样的东西......

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    
        if(self.isFiltered) //If searching
            return nil; //Return empty section
        else
            return sectionSelectionArray; //Return list of headers
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多