加入指數(IOS開發)

來源:互聯網
上載者:User

標籤:

該指數是用來協助查詢。

原則上:

- 索引的標題是不完全一樣的標題顯示;

- 指數應該具有一定的代表性,它可表示一組資料;

- 假設索引列表視圖。在一般情況下不再使用擴充視圖。

(easy指向)

會又一次到的資料來源方法:

tableView: numberOfRowsInSection: ------擷取某節的行數

tableView:cellForRowAtIndexPath: -------Cell資料的實現

numberofSectionInTableView: ----------擷取節數

tableView:titleForHeaderInSection: --------區段標頭

sectionIndexTitlesForTableView: --------擷取索引


watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl5YWt1bjE5OTA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >


@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        NSBundle *bundle = [NSBundle mainBundle];    NSString *plistPath = [bundle pathForResource:@"team_dictionary"                                           ofType:@"plist"];        // 擷取屬性列表檔案裡的所有資料    self.dicData = [[NSDictionary alloc] initWithContentsOfFile:plistPath];    NSArray *tempList = [self.dicData allKeys];    // 對key進行排序    // selector為SEL類型,sortedArrayUsingSelector方法的參數必須是selector    self.listGroupname = [tempList sortedArrayUsingSelector:@selector(compare:)];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}#pragma mark 重寫資料來源方法- (NSInteger) tableView: (UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    // 依照節索引從小組名數組中獲得組名    NSString *groupName = [self.listGroupname objectAtIndex:section];    // 將組名作為key,從字典中取出球隊數組集合    // 由於儲存的時候是雜湊結構    NSArray *listTeams = [self.dicData objectForKey:groupName];    // 這一節一共同擁有多少球隊    return [listTeams count];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *CellIdentifier = @"CellIdentifier";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];    if (cell == nil) {        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];    }        // 獲得選擇的節 A組即第1節    NSUInteger section = [indexPath section];    // 獲得選擇節中選中的行索引 -- A組第1、第2.。

。

NSUInteger row = [indexPath row]; // 依照節索引從小組名數組中獲得組名 -- A組 NSString *groupName = [self.listGroupname objectAtIndex:section]; // 將組名作為key,從字典中取出球隊數組集合 NSArray *listTeams = [self.dicData objectForKey:groupName]; cell.textLabel.text = [listTeams objectAtIndex:row]; return cell;}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ // 該節行數 return [self.listGroupname count];}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ // 該節的節頭 NSString *groupName = [self.listGroupname objectAtIndex:section]; return groupName;}- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ // 加入索引 NSMutableArray *listTitles = [[NSMutableArray alloc] initWithCapacity:[self.listGroupname count]]; // 把A組改為A for (NSString *item in self.listGroupname) { NSString *title = [item substringToIndex:1]; // 擷取的第一個字元 [listTitles addObject: title]; // 字串數組追加的最後位置 } return listTitles;}@end


注意:

在這個故事中要配置版本tableview委託協議。。!!

加入指數(IOS開發)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.