欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS tableView右側(cè)索引視圖狀態(tài)獲取的方法實(shí)例

 更新時(shí)間:2021年07月01日 16:56:59   作者:豪冷啊  
tableView用于顯示一個(gè)垂直滾動(dòng)的單元格數(shù)(通常為可重復(fù)使用的單元格)組成的視圖,這篇文章主要給大家介紹了關(guān)于iOS tableView右側(cè)索引視圖狀態(tài)獲取的相關(guān)資料,需要的朋友可以參考下

前言

在iPhone和其他iOS的很多程序中都會(huì)看到Table View的出現(xiàn),除了一般的表格資料展示之外,設(shè)置的屬性資料往往也用到Table View,Table View主要分為以下兩種:

 Plain:這是普通的列表風(fēng)格
 Grouped :這是分塊風(fēng)格。

本文介紹的是iOS tableView右側(cè)索引視圖狀態(tài)獲取的相關(guān)內(nèi)容,下面來(lái)看正文

需求

一圖勝千言!

在觸摸右側(cè)索引欄時(shí)

需要展示對(duì)應(yīng)的組號(hào)名稱(chēng)

手指離開(kāi)時(shí)消失

實(shí)現(xiàn)

通過(guò)Xcode查看視圖層次結(jié)構(gòu)

右側(cè)索引視圖的繼承關(guān)系

是這樣的:

UITableViewIndex
UIControl
UIView
UIResponder
NSObject

很顯然UITableViewIndex 是私有的

但是UIControl 是公開(kāi)的

于是

通過(guò)遍歷tableView的子視圖來(lái)獲取它

- (void)reloadData
{
    [_tableView reloadData];
    
    for (UIView *view in _tableView.subviews) {
        if ([view isKindOfClass:[UIControl class]]) {
            _indexControl = (UIControl *)view;
        }
    }
}

接著

在代理方法里面

處理相關(guān)邏輯就OK了

/// 點(diǎn)擊右側(cè)索引時(shí)的代理方法
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    _sectionLabel.text = title;  // 顯示 組號(hào)標(biāo)題 的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) { // 沒(méi)有觸摸時(shí),隱藏它
            _sectionLabel.hidden = YES;
        }
    });
    
    return index;
}

總結(jié)

到此這篇關(guān)于iOS tableView右側(cè)索引視圖狀態(tài)獲取的文章就介紹到這了,更多相關(guān)iOS tableView索引視圖狀態(tài)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論