UITableView 索引的添加 sectionIndexTitlesForTableView sectionIndexColor


標簽: 

it

 

表格索引

 

sectionindextitlesfo

 

sectionindexcolor

分類: iOS

1、自定義索引

准備數據,設計一個數組,數組里面的元素為每個section的數組。

//返回Section總數

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return self.indextitles.count;

}

//返回每個Section的行數

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [[self.sectionarray objectAtIndex:section] count];

}

//返回每個Section的title

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    return [self.indextitles objectAtIndex:section];

}

//返回索引欄數據

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

    return self.indextitles;

}

//建立索引欄和section的關聯

-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index

{

    return [self.indextitles indexOfObject:title];

}

2、使用UILocalizedIndexedCollation建立
創建一個UILocalizedIndexedCollation  這個其實固定為27個字符 A-Z 加 #  換句話說,就是索引欄固定為A-Z 加 #,創建的表格一定有27個Section,如果沒有數據的話會有titleForHeaderInSection
//返回Section總數

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [self.collation.sectionTitles count];

}

//返回每個Section的title

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    return [self.collation.sectionIndexTitles objectAtIndex:section];

}

//返回索引欄的列別數據

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    return self.collation.sectionTitles;

}

//建立關聯

-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index {

    return [self.collation sectionForSectionIndexTitleAtIndex:index];

}

//每個Section的行數

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSArray *innerArray = [self.outerArray objectAtIndex:section];

    return [innerArray count];

}

 

if ([self.tableViewrespondsToSelector:@selector(sectionIndexColor)])

    {

        self.tableView.sectionIndexColor=[UIColor colorWithHue:(136.0/360.0)  // Slightly bluish green

                                                   saturation:1.0

                                                   brightness:0.60

                                                        alpha:1.0];

 

    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM