需求
一图胜千言!

在触摸右侧索引栏时
 需要展示对应的组号名称 手指离开时消失
实现
通过Xcode查看视图层次结构 右侧索引视图的继承关系
 是这样的:
UITableViewIndex
UIControl
UIView
UIResponder
NSObject
很显然UITableViewIndex 是私有的
 但是UIControl 是公开的
于是
 通过遍历tableView的子视图来获取它
- (void)reloadData
{
[_tableView reloadData];
for (UIView *view in _tableView.subviews) {
if ([view isKindOfClass:[UIControl class]]) {
_indexControl = (UIControl *)view;
}
}
}
接着
 在代理方法里面
 处理相关逻辑就OK了
/// 点击右侧索引时的代理方法
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
_sectionLabel.text = title; // 显示 组号标题 的Label
if (_sectionLabel.hidden) { // 隐藏了,显示它
_sectionLabel.hidden = NO;
}
// 延迟 1 秒隐藏
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// isTracking: A Boolean value indicating whether the control is currently tracking touch events.
if (!_indexControl.isTracking) { // 没有触摸时,隐藏它
_sectionLabel.hidden = YES;
}
});
return index;
}
一个有趣的点赞动画
https://github.com/xjh093/JHLikeButton
                










