iOS|iOS tableView右侧索引视图状态获取的方法实例
前言
在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View主要分为以下两种:
文章图片
Plain:这是普通的列表风格
Grouped :这是分块风格。
本文介绍的是iOS tableView右侧索引视图状态获取的相关内容,下面来看正文
需求
一图胜千言!
在触摸右侧索引栏时
需要展示对应的组号名称
手指离开时消失
实现
通过Xcode查看视图层次结构
右侧索引视图的继承关系
是这样的:
UITableViewIndex很显然UITableViewIndex 是私有的
UIControl
UIView
UIResponder
NSObject
但是UIControl 是公开的
于是
通过遍历tableView的子视图来获取它
- (void)reloadData{[_tableView reloadData]; for (UIView *view in _tableView.subviews) {if ([view isKindOfClass:[UIControl class]]) {_indexControl = (UIControl *)view; }}}
接着
在代理方法里面
【iOS|iOS tableView右侧索引视图状态获取的方法实例】处理相关逻辑就OK了
/// 点击右侧索引时的代理方法- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{_sectionLabel.text = title; // 显示 组号标题 的Labelif (_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右侧索引视图状态获取的文章就介绍到这了,更多相关iOS tableView索引视图状态内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- tableView|tableView 头视图下拉放大 重写
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 接口|axios接口报错-参数类型错误解决
- iOS|iOS 笔记之_时间戳 + DES 加密
- iOS,打Framework静态库