IOS UITableView 高仿微信右側(cè)滑動定位內(nèi)容

前言:最近接了一個新項目、項目中有一個需求就是一個UITableView右側(cè)滑動索引定位TableView分區(qū)內(nèi)容、好了、相信大家對這個功能點都有所了解以及見過、那么做成微信的形式咱們是不是得自定義呀、好了、上代碼。

#pragma mark - UITableView Delegate
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    static NSString *identfier = @"XCLeagueFilterCell";
    XCLeagueFilterCell *cell = [tableView dequeueReusableCellWithIdentifier:identfier];
    if (cell == nil) {
        cell = [[XCLeagueFilterCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identfier];
    }
    NSString *key = self.groupNameArr[indexPath.section];
    NSArray *valueArr = [self.dataDic objectForKey:key];
    cell.titlelabel.text = [NSString stringWithFormat:@"%@", valueArr[indexPath.row]];
    cell.deatilLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row];
    // 第一行顯示
    if (indexPath.row == 0) {
        cell.topLineLabel.hidden = NO;
    } else {
        cell.topLineLabel.hidden = YES;
    }
    [cell.logonIv setImage:XCImage(@"score_icon_liansai")];
    return cell;
}

#pragma mark 索引列點擊事件
// 手指滑動及點擊字母相應的代理
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
    //點擊索引,列表跳轉(zhuǎn)到對應索引的行
    if ([title isEqualToString:@"熱門"]) {
        return self.groupNameArr.count;
    }
    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    //[XCProgressHUD showSuccess:title];
    return index;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [self.groupNameArr objectAtIndex:section];
}

// 索引標題就是右側(cè)的A-Z 字母
- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    NSMutableArray *listTitlesArray = [[NSMutableArray alloc] initWithCapacity:[self.groupNameArr count]];
    for (NSString *item in self.groupNameArr) {
        [listTitlesArray addObject:item];
    }
    return listTitlesArray;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *key = self.groupNameArr[section];
    NSArray *valueArr = [self.dataDic objectForKey:key];
    return valueArr.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.groupNameArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

圖片中已經(jīng)注釋了幾個重點的代理方法、如需要其他功能定制則實現(xiàn)系統(tǒng)其他代理方法。下載地址:https://github.com/chenxuhunoc/WeChatDragIndex

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容