iOS tableView右侧索引视图状态获取的方法实例

tableView用于显示一个垂直滚动的单元格数(通常为可重复使用的单元格)组成的视图,这篇文章主要给大家介绍了关于iOS tableView右侧索引视图状态获取的相关资料,需要的朋友可以参考下

前言

在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View主要分为以下两种:

 Plain:这是普通的列表风格
 Grouped :这是分块风格。

本文介绍的是iOS tableView右侧索引视图状态获取的相关内容,下面来看正文

需求

一图胜千言!

在触摸右侧索引栏时

需要展示对应的组号名称

手指离开时消失

实现

通过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; } 

总结

以上就是iOS tableView右侧索引视图状态获取的方法实例的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 移动