麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

iOS.UIKit.15.UITableView--Index

2019-11-14 20:26:24
字體:
來源:轉載
供稿:網友

1、案例介紹:具備索引功能的分節表視圖,如圖01

圖01

2、team_dictionary.plist

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PRopertyList-1.0.dtd"><plist version="1.0"><dict>    <key>A組</key>    <array>        <string>A1-南非</string>        <string>A2-墨西哥</string>        <string>A3-烏拉圭</string>        <string>A4-法國</string>    </array>    <key>B組</key>    <array>        <string>B1-阿根廷</string>        <string>B2-尼日利亞</string>        <string>B3-韓國</string>        <string>B4-希臘</string>    </array>    <key>C組</key>    <array>        <string>C1-英格蘭</string>        <string>C2-美國</string>        <string>C3-阿爾及利亞</string>        <string>C4-斯洛文尼亞</string>    </array>    <key>D組</key>    <array>        <string>D1-德國</string>        <string>D2-澳大利亞</string>        <string>D3-塞爾維亞</string>        <string>D4-加納</string>    </array>    <key>E組</key>    <array>        <string>E1-荷蘭</string>        <string>E2-丹麥</string>        <string>E3-日本</string>        <string>E4-喀麥隆</string>    </array>    <key>F組</key>    <array>        <string>F1-意大利</string>        <string>F2-巴拉圭</string>        <string>F3-斯洛伐克</string>        <string>F4-新西蘭</string>    </array>    <key>G組</key>    <array>        <string>G1-巴西</string>        <string>G2-朝鮮</string>        <string>G3-科特迪瓦</string>        <string>G4-葡萄牙</string>    </array>    <key>H組</key>    <array>        <string>H1-西班牙</string>        <string>H2-瑞士</string>        <string>H3-洪都拉斯</string>        <string>H4-智利</string>    </array></dict></plist>

3、.h

#import <UIKit/UIKit.h>@interface CQ24ViewController : UITableViewController<UISearchBarDelegate>// 表數據@property (strong,nonatomic) NSDictionary *dictData;// 表數據分組名集合@property (strong,nonatomic) NSArray *listGroupname;@end

4、.m

 

#import "CQ24ViewController.h"@interface CQ24ViewController ()@end@implementation CQ24ViewController- (void)viewDidLoad{    [super viewDidLoad];        NSBundle *mainBundle = [NSBundle mainBundle];    NSString *plistPath = [mainBundle pathForResource:@"team_dictionary" ofType:@"plist"];        // 1、初始化表格數據dictData    self.dictData = [[NSDictionary alloc] initWithContentsOfFile:plistPath];    // 2、初始化分組名稱,排序    NSArray *tempList = [self.dictData allKeys];    self.listGroupname = [tempList sortedArrayUsingSelector:@selector(compare:)];    }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];}#pragma mark 返回分組數- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    // 1、獲取分組名稱    NSString *groupName = [self.listGroupname objectAtIndex:section];    // 2、將分組名稱作為key,從字典中取出分組數據    NSArray *listTeams = [self.dictData objectForKey:groupName];    return [listTeams count];    }#pragma mark 填充每個節的Cell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    // 1、加載一個cell    static NSString *CellIdentifier = @"CellIdentifier";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    if (cell == nil) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];    }    // 2、獲取選擇的節    NSUInteger section = [indexPath section];    // 3、獲取節名稱    NSString *groupName = [self.listGroupname objectAtIndex:section];    // 4、獲取節數據    NSArray *listTeams = [self.dictData objectForKey:groupName];    // 5、獲取選中節中的行索引    NSUInteger row = [indexPath row];    // 6、設置cell中的text    cell.textLabel.text = [listTeams objectAtIndex:row];    return cell;}#pragma mark 節數- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return self.listGroupname.count;}#pragma mark 設置節title-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{    NSString *groupName = [self.listGroupname objectAtIndex:section];    return groupName;}#pragma mark 索引- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{    // 1、存在索引的集合    NSMutableArray *listTitles = [[NSMutableArray alloc] initWithCapacity:[self.listGroupname count]];    // 2、初始化索引集合    for (NSString *item in self.listGroupname) {        NSString *title = [item substringToIndex:1];        [listTitles addObject:title];    }    return listTitles;}@end

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产激爽大片在线播放 | 国产一国产一级毛片视频在线 | 久久久久免费精品 | 99精品视频在线观看免费 | av在线1| 成人精品一区二区三区中文字幕 | 亚洲精品在线观看免费 | 污黄视频在线观看 | 看个毛片| 精品人人人人 | 羞羞视频免费入口网站 | 国色天香综合网 | 精品亚洲国产视频 | 男女污污视频网站 | 精品国产一二区 | 精品一区二区三区电影 | 狠狠操精品视频 | 日本高清在线播放 | www.91在线| 国产午夜精品一区 | 玖草在线资源 | 欧美激情图区 | 国产成人自拍视频在线观看 | 久久久久久久一区二区三区 | 国产在线精品区 | 九色com| 欧美日韩在线视频一区二区 | 日日做夜夜操 | 欧美日韩专区国产精品 | 中文字幕免费在线观看视频 | 国产韩国精品一区二区三区久久 | www国产免费 | 高清视频91 | 久久一本日日摸夜夜添 | 激情亚洲一区二区三区 | 一级毛片在线免费观看视频 | 31freehdxxxx欧美| 成人午夜在线观看视频 | av成人在线播放 | 国产视频在线观看一区二区三区 | 亚洲视频观看 |